June
20
2015

A simple player control using a Character Controller component.

In this tutorial, we’ll create a schematic to control our player using a Character Controller component. The control will allow to move the player around (with the player facing into the move direction) and jumping.

You can download the finished schematic here – if the schematic is missing the script reference after importing it into your project, just select the MakinomSchematicAsset class in the missing script field.

Download Schematic

Schematic

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

schematics_simple_character_control1

Check Variables

Add > Value > Variable > Check Variables

First, we’ll check if we’re currently jumping – in that case we’ll just continue to move the game object upwards.

Jumping will set an object variable on the game object to the current time + an offset, when the current time exceeds that value, we’ll stop moving upwards.

  • Condition Type
    Select Variable.
  • Variable Key
    Set to jumpTime.
  • Variable Origin
    Select Object.
  • Object
    Select Machine Object.
  • Is Valid
    Enable this setting.
  • Exists
    Disable this setting.
  • Type
    Select Float.
  • Check Type
    Select Is Less.
  • Float Type
    Select Time.

Check On Ground

Add > Movement > Movement > Check On Ground

We’re not jumping, so let’s check if we’re on the ground to see if we can jump. Since we’re using a Character Controller component, we can check if we’re on the ground without using a raycast.

This node is connected to the Success slot of the Check Variables node.

  • Object
    Select Machine Object.
  • Use Raycast
    Disable this setting.

Input Key

Add > Input > Input Key

We’re on the ground, so let’s check if the player pressed jump.

This node is connected to the On Ground slot of the Check On Ground node.

  • Input Key
    Select Jump.

Move

Add > Movement > Movement > Move

We’re in the air (falling) or on the ground and the player isn’t jumping, we’ll just move normally using the player’s input.

This node is connected to the In Air slot of the Check On Ground node and to the Failed slot of the Input Key node.

Moving Object

  • Object
    Select Machine Object.
  • Move Component
    Select Character Controller.

Move Change

  • Vector3 Type
    Select Set Axis.
  • X-Axis
    Select Input Key Axis and Horizontal.
  • Y-Axis
    Set to 0 (Value).
  • Z-Axis
    Select Input Key Axis and Vertical.

Speed Settings

  • Speed
    Set to 5 (Value).
    You can also use a float variable where you’ve stored your desired movement speed (or a different value).
  • Clamp Magnitude
    Enable this setting.

Gravity

  • Add Gravity
    Enable this setting.
  • Vector3 Type
    Select Value.
  • Value
    Set to X=0, Y=-9.81, Z=0.
  • Use Delta Time
    Enable this setting.
  • Local Space
    Disable this setting.

Rotation Settings

  • Face Direction
    Enable this setting.
  • Rotation Component
    Select Auto.
  • Lock X-Axis Rotation
    Enable this setting.
  • Lock Y-Axis Rotation
    Disable this setting.
  • Lock Z-Axis Rotation
    Enable this setting.

Change Variables

Add > Value > Variable > Change Variables

The player pressed jump, so let’s set the time to remember when to stop moving upwards.

This node is connected to the Jump slot of the Input Key node.

  • Change Type
    Select Variable.
  • Variable Key
    Set to jumpTime.
  • Variable Origin
    Select Object.
  • Object
    Select Machine Object.
  • Type
    Select Float.
  • Operator
    Select Set.
  • Float Type
    Select Time and 0.25.
    This sets the variable to the current time (since application start) + 0.25 seconds.

Move

Add > Movement > Movement > Move

The player is jumping (i.e. moving upwards), but we also use the player’s input to move. Since this is a simple control, the jump will set the Y-axis to 2, using the double of the movement speed for jumping.

This node is connected to the Next slot of the Change Variables node and to the Failed slot of the Check Variables node.

Moving Object

  • Object
    Select Machine Object.
  • Move Component
    Select Character Controller.

Move Change

  • Vector3 Type
    Select Set Axis.
  • X-Axis
    Select Input Key Axis and Horizontal.
  • Y-Axis
    Set to 2 (Value).
  • Z-Axis
    Select Input Key Axis and Vertical.

Speed Settings

  • Speed
    Set to 5 (Value).
    You can also use a float variable where you’ve stored your desired movement speed (or a different value).
    Note that the the jump speed will be twice that value.
  • Clamp Magnitude
    Disable this setting.

Gravity

  • Add Gravity
    Disable this setting.
  • Use Delta Time
    Enable this setting.
  • Local Space
    Disable this setting.

Rotation Settings

  • Face Direction
    Disable this setting.

And that’s it – click on Save Schematic and e.g. save it as SimpleControl.

Tick Machine

The schematic needs to be added using a tick machine. Don’t forget to also add an Object Variables component to the game object.

Add a tick machine component to the game object (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 Schematics.
  • Schematics Asset
    Select SimpleControl (or however you named your schematic).
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

And that’s it.