Setting up the background scroll schematic.

In this short, final tutorial, we’ll make the background scroll for a better visual feedback to moving through space.

BG Scroll: Schematic

The schematic will use local start variables that define the start position, scroll speed and size of the background. We’ll need them for the scrolling mechanic.

Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.

space_shooter_11_moving_the_background1

Settings

We’ll set up local variables as Machine Start Variables for easy setup in the machine component at a later time. When using the schematic in a machine component, the defined start variables will be added automatically, using their default values.

Machine Start Variables

Click on Add Start Variable to add a local start variable that will be exposed to the machine component’s inspector.

  • Variable Key
    Set to startPosition.
  • Type
    Select Vector3.
  • Default Value
    Set to X=0, Y=-10, Z=0.

Again, click on Add Start Variable to add another local start variable.

  • Variable Key
    Set to scrollSpeed.
  • Type
    Select Float.
  • Default Value
    Set to -0.25.

Copy the previous start variable and change the following settings.

  • Variable Key
    Set to tileSizeZ.
  • Default Value
    Set to 30.

Change Variables

Add > Value > Variable > Change Variables

We’ll do a first calculation for the new scroll positition by multiplying the scroll speed with the current time.

Click on Add Variable to add a variable change.

  • Change Type
    Select Variable.
  • Variable Key
    Select scrollPosition.
  • Variable Origin
    Select Local.
  • Type
    Select Float.
  • Operator
    Select Set.
  • Float Value
    Select Float Variable.
  • Variable Key
    Set to scrollSpeed.
  • Variable Origin
    Select Local.

Copy the variable change and change the following settings.

  • Operator
    Select Multiply.
  • Float Value
    Select Time.

Float Ping Pong

Add > Value > Float > Float Ping Pong

This node will ping pong or loop a float value between two defined values and store it into a variable. We’ll use it to loop the scroll position according to the tile size.

  • Use Repeat
    Enable this setting.
    We want to loop instead of ping pong the value.

Variable Settings

  • Variable Key
    Set to scrollPosition.
  • Variable Origin
    Select Local.
  • Operator
    Select Set.

Value

  • Value
    Select Float Variable.
  • Variable Key
    Set to scrollPosition.
  • Variable Origin
    Select Local.

Length

  • Value
    Select Float Variable.
  • Variable Key
    Set to tileSizeZ.
  • Variable Origin
    Select Local.

Change Variables

Add > Value > Variable > Change Variables

Now, we’ll store the new position the background object will be set to into a Vector3 variable.

Click on Add Variable to add a variable change.

  • Change Type
    Select Variable.
  • Variable Key
    Select newPosition.
  • Variable Origin
    Select Local.
  • Type
    Select Vector3.
  • Operator
    Select Set.
  • Float Value
    Select Vector3 Variable.
  • Variable Key
    Set to startPosition.
  • Variable Origin
    Select Local.

Copy the variable change and change the following settings.

  • Type
    Select Axis Vector3.
  • Axis
    Select X.
  • Operator
    Select Add.
  • Float Value
    Select Float Variable.
  • Variable Key
    Set to scrollPosition.
  • Variable Origin
    Select Local.

Change Position

Add > Movement > Movement > Change Position

Finally, we’ll place the background object at the new position.

Moving Object

  • Object
    Select Machine Object.
  • Movement Component
    Select Transform.

Target Position

  • To Object
    Disable this setting.
  • Vector3 Type
    Select Vector3 Variable.
  • Variable Key
    Set to newPosition.
  • Variable Origin
    Select Local.

And that’s it for the schematic – click on Save Schematic and save it as BGScroll in Assets/Schematics/.

BG Scroll: Tick Machine

All that’s left to do is adding the schematic to the Background game object in the scene. We’ll use a tick machine component to adjust the position each frame.

Add the component (e.g. using the component menu: Makinom > Machines > Tick Machine) and change the following settings.

Start Settings

  • Update
    Enable this setting.

Machine Execution Settings

  • Asset Type
    Select Schematic.
  • Schematic Asset
    Select BGScroll.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Local Start Variables

The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values – since the default values are already what we need, we don’t have more to do here. Make sure all variables are enabled.

And that’s it – don’t forget to save the scene.

Testing

Click on Play to test the game. You’ll now notice the background scrolling at a slow speed.

This concludes the space shooter game tutorial series for now. You can add additional content to the game, e.g. different levels, more enemies or power ups (like increasing the player’s health or decreasing the fire rate).