Makinom - Game Toolkit for Unity
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • Extensions
    • API
  • Makinom 1
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get Makinom

Guide

Schematics

  • Setting the Player
  • Simple Character Controller
  • Mouse Orbit Camera
  • Random Waypoints

Breakout

  • Breakout Tutorial Introduction
  • 01 First Steps
  • 02 Player Controls
  • 03 Bricks
  • 04 Losing a Life
  • 05 UI Setup
  • 06 Sound Assignments

Space Shooter

  • Space Shooter Tutorial Introduction
  • 01 First Steps
  • 02 Player Move Controls
  • 03 Player Weapon Controls
  • 04 Hit and Destroy
  • 05 Asteroids
  • 06 Game Controller
  • 07 UI Setup
  • 08 Player’s Destruction
  • 09 Enemy Ship Mechanics
  • 10 Enemy Ship
  • 11 Moving the Background

Match 3

  • Match 3 Tutorial Introduction
  • 01 First Steps
  • 02 UI Setup
  • 03 Generating the Level
  • 04 Matching Jewels
  • 05 Destroying Jewels
  • 06 Game Controls
  • 07 Jewel Setup

Survival Shooter

  • Survival Shooter Tutorial Introduction
  • 01 First Steps
  • 02 Player Movement
  • 03 Player Shooting
  • 04 Enemy Mechanics
  • 05 Setting up the Enemies
  • 06 UI Setup
  • 07 Player’s Death
  • 08 Enemy Spawner

2D Roguelike

  • 2D Roguelike Tutorial Introduction
  • 01 First Steps
  • 02 Generating the Level
  • 03 Level Generation Machines
  • 04 Player Controls
  • 05 Walls, Food and Exit
  • 06 Game Manager and UI Setup
  • 07 Enemy Mechanics
  • 08 Game Over

2D Platformer

  • 2D Platformer Tutorial Introduction
  • 01 First Steps
  • 02 Player Movement
  • 03 Camera and Background
  • 04 Shooting Rockets
  • 05 Enemy Mechanics
  • 06 Setting up the Enemies
  • 07 Enemy Spawners
  • 08 Player Damage and Fall Remover
  • 09 Health Pickup
  • 10 Bomb Pickup
  • 11 Bomb Prefabs and Lay Bombs
  • 12 Pickup Spawner
  • 13 UI Setup
  • 14 Background Animations
  • Home
  • Guide
  • Tutorials
  • Space Shooter
  • 02 Player Move Controls

02 Player Move Controls

Table of Contents
  • Basic Player Setup
    • Object Variables
    • Setting Player Schematic
  • Player Mover: Schematic
    • Settings
      • Machine Start Variables
    • Vector3 Multiply
      • Variable Settings
      • Vector3 Value
      • Multiply By
    • Rigidbody Change Velocity
      • Rigidbody Object
      • Velocity
    • Clamp Transform
      • Clamp Object
      • Clamp X-Axis
      • Clamp Z-Axis
    • Change Variables
    • Rigidbody Move Rotation
      • Rigidbody Object
      • Rotation
  • Player Mover: Tick Machine
    • Start Settings
    • Machine Execution Settings
    • Local Start Variables
  • Testing

Setting up the player’s movement controls.

In this tutorial we’ll do the basic player setup and create a schematic to control the movement.

Basic Player Setup #

The player’s basic setup involves adding object variables to store the player’s attributes and adding a simple schematic to set the player. Place the Player prefab (found at Assets/Tutorial Resources/Prefabs/) in the scene and position it at X=0, Y=0, Z=0.

Object Variables #

First, we’ll add object variables to the player’s game object. Add an Object Variables component (e.g. using the component menu: Makinom > Scenes > Object Variables).

Change the following settings of the object variables component.

  • Local Variables
    Disable this setting.
  • Object ID
    Set to player.
  • Always Initialize
    Enable this setting.

Click on Add Variable to add a new variable to the object variables. This variable will be used to store the player’s health. When the health reaches 0, the player’s ship will be destroyed.

  • Variable Key
    Set to health.
  • Type
    Select Int.
  • Operator
    Select Set.
  • Float Value
    Set to 1.
    Using the Value float type.

Again, click on Add Variable. This variable will be used to store the player’s fire rate (i.e. time between shots).

  • Variable Key
    Set to fireRate.
  • Type
    Select Float.
  • Operator
    Select Set.
  • Float Value
    Set to 0.25.
    Using the Value float type.

Setting Player Schematic #

Now, we’ll use a schematic to set the player when the level starts and add it with an Auto Machine component.

Follow the steps in this schematic tutorial – it explains how to create the schematic and add an auto machine to the game object.

Player Mover: Schematic #

Next, we’ll create a schematic to handle the player’s movement control. Open the Makinom editor, navigate to Schematics and create a new schematic.

The player’s game object will be moved by changing the Rigidbody component’s velocity. Additionally, we’ll tilt the game object according to the horizontal movement.

Please note that the machine component used to play the schematic will set up some of the used local variables.

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.

These variables will be used for the player’s movement (speed, tilt) and limiting the area the player can move in.

  • Variable Key
    Set to speed.
  • Type
    Select Float.
  • Default Value
    Set to 10.

Copy the previous start variable and change the following settings.

  • Variable Key
    Set to tilt.
  • Default Value
    Set to –5.

Again, copy the previous start variable and change the following settings.

  • Variable Key
    Set to xMin.
  • Default Value
    Set to -6.

Again, copy the previous start variable and change the following settings.

  • Variable Key
    Set to xMax.
  • Default Value
    Set to 6.

Again, copy the previous start variable and change the following settings.

  • Variable Key
    Set to zMin.
  • Default Value
    Set to -4.

Again, copy the previous start variable and change the following settings.

  • Variable Key
    Set to zMax.
  • Default Value
    Set to 8.

Vector3 Multiply #

Add Node > Value > Vector > Vector3 Multiply

This node will multiply a Vector3 value with a float value and store it into a Vector3 variable.

We’ll use the player’s input as a Vector3 value, multiply it by the movement speed (will be defined as start variable in the machine component) and store it into a local Vector3 variable. This will be the velocity used to move the player’s game object.

Variable Settings #

The Variable Settings define where the Vector3 value will be stored.

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

Vector3 Value #

Now, we’ll define the Vector3 value using the player’s input.

  • Vector3 Type
    Select Value > Set Axis.
    This allows us to individually define the X, Y and Z axis if the Vector3.
  • X-Axis
    Select Input > Input Key Axis and Horizontal.
  • Y-Axis
    Set to 0 (Value).
  • Z-Axis
    Select Input > Input Key Axis and Vertical.

Multiply By #

Finally, we’ll multiply the defined Vector3 value by a float value, using a local variable.

  • Multiply By
    Select Variable > Float Variable.
  • Variable Key
    Set to speed.
  • Variable Origin
    Select Local.

Rigidbody Change Velocity #

Add Node > Game Object > Rigidbody > Rigidbody Change Velocity

This node will set the velocity of a rigidbody component. We’ll set the player’s velocity to the Vector3 value we’ve just stored into the local Vector3 variable velocity.

Rigidbody Object #

  • Object
    Select Machine Object.

Velocity #

  • Vector3 Type
    Select Vector3 Variable.
  • Variable Key
    Set to velocity.
  • Variable Origin
    Select Local.

Clamp Transform #

Add Node > Movement > Movement > Clamp Transform

This node will make sure the player’s position stays within a defined area. We’ll use local float variables defined as start variables in the machine component for that.

Clamp Object #

  • Object
    Select Machine Object.
  • Value Origin
    Select Position.
    We’ll clamp the position of the game object.

Clamp X-Axis #

  • Clamp X-Axis
    Enable this setting.
  • X-Axis Minimum
    Select Variable > Float Variable.
  • Variable Key (X-Axis Minimum)
    Set to xMin.
  • Variable Origin (X-Axis Minimum)
    Select Local.
  • X-Axis Maximum
    Select Variable > Float Variable.
  • Variable Key (X-Axis Maximum)
    Set to xMax.
  • Variable Origin (X-Axis Maximum)
    Select Local.

Clamp Z-Axis #

  • Clamp Z-Axis
    Enable this setting.
  • Z-Axis Minimum
    Select Variable > Float Variable.
  • Variable Key (Z-Axis Minimum)
    Set to zMin.
  • Variable Origin (Z-Axis Minimum)
    Select Local.
  • Z-Axis Maximum
    Select Variable > Float Variable.
  • Variable Key (Z-Axis Maximum)
    Set to zMax.
  • Variable Origin (Z-Axis Maximum)
    Select Local.

Change Variables #

Add Node > Value > Variable > Change Variables

This node will change variables. We’ll multiply the X-axis of the velocity by the local float variable tilt (start variable).

Click on Add Variable to add a variable change.

  • Change Type
    Select Variable.
    We’ll directly define a variable change.
  • Variable Key
    Select velocity.
  • Variable Origin
    Select Local.
  • Type
    Select Axis Vector3.
    This allows to change an individual axis of a Vector3 variable.
  • Axis
    Select X.
  • Operator
    Select Multiply.
  • Float Value
    Select Variable > Float Variable.
  • Variable Key
    Set to tilt.
  • Variable Origin
    Select Local.

Rigidbody Move Rotation #

Add Node > Game Object > Rigidbody > Rigidbody Move Rotation

This node will rotate the rigidbody. We’ll only rotate it on the Z-axis, using the X-axis of the velocity variable.

Rigidbody Object #

  • Object
    Select Machine Object.

Rotation #

  • Vector3 Type
    Select Value > Set Axis.
  • X-Axis
    Set to 0 (Value).
  • Y-Axis
    Set to 0 (Value).
  • Z-Axis
    Select Variable > Vector3 Variable and X.
  • Variable Key
    Set to velocity.
  • Variable Origin
    Select Local.

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

Player Mover: Tick Machine #

The player is moved using a Rigidbody component, i.e. we’ll need to Fixed Update for the physics updates.

Add a Tick Machine component to the player’s game object (e.g. using the component menu: Makinom > Machines > Tick Machine). Change the following settings.

Start Settings #

  • Fixed Update
    Enable this setting.
    The machine will be started in the fixed framerate frame.

Machine Execution Settings #

  • Schematic Asset
    Select PlayerMover.
  • Execution Type
    Select Single.
    The machine can only be executed once at a time.
  • Update Type
    Select Fixed 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 for now – apply the changes to the prefab by clicking on Overrides > Apply All (top of the inspector).

Testing #

Click on Play to test the game. You’ll be able to move the player around in a limited area of the screen.

The next tutorial will handle the player weapon controls.

Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Updated on December 17, 2020
Table of Contents
  • Basic Player Setup
    • Object Variables
    • Setting Player Schematic
  • Player Mover: Schematic
    • Settings
      • Machine Start Variables
    • Vector3 Multiply
      • Variable Settings
      • Vector3 Value
      • Multiply By
    • Rigidbody Change Velocity
      • Rigidbody Object
      • Velocity
    • Clamp Transform
      • Clamp Object
      • Clamp X-Axis
      • Clamp Z-Axis
    • Change Variables
    • Rigidbody Move Rotation
      • Rigidbody Object
      • Rotation
  • Player Mover: Tick Machine
    • Start Settings
    • Machine Execution Settings
    • Local Start Variables
  • Testing
Sitemap
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • Extensions
    • API
  • Makinom 1 Hub
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get Makinom
  • Contact
  • Blog
  • ORK Framework
  • gamingislove.com
Categories
  • Makinom 1 (97)
    • Tutorial (97)
      • 2D Platformer (14)
      • 2D Roguelike (8)
      • Breakout (6)
      • How-to (34)
      • Match 3 (6)
      • Schematic (4)
      • Scripting (6)
      • Space Shooter (11)
      • Survival Shooter (8)
  • News (11)
  • Release (68)
Search

© 2015 Gaming is Love e.U.

Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!