Moving A Cube

See Logic Node Editor for node basics.

Moving an object requires input from user, processing this input, and applying movement to object. To run the game, a Camera object is also required.

  • Add 4 Keyboard Key nodes, and assign A for left, D for right, W for forward, and S for backward movement.

  • Add 2 Math nodes, set both to Subtract, and connect 2 above nodes to each Math node, i.e. A and D nodes to one Math node, W and S to the other Math node.

  • Next add a Combine XY, connect above Math nodes to X and Y input sockets.

  • Connect to Vector Math Vector 1 socket, set Normalize property from dropdown menu.

  • Connect the Result output to another Vector Math node > Vector 1 socket. Set property to Scale.

    Tip

    Either add new node, or select existing one > Shift-D to duplicate > move with mouse > LMB to ‘land’ it. Keep mouse cursor close to the node while duplicating.

  • Add Float node, set value to 0.1, and connect it to the last Vector Math node, Scale input. This will determine movement speed for the object.

  • Add Apply Movement node; output from above Vector Math node goes into Vector input. Check Local box, and in the Object input select an object to move, i.e. Cube.

  • Last, add On Update node, and connect to above Apply Movement > Condition socket.

Alright, now we apply this logic tree to an object.

  • Select (or add) any object, in Logic Nodes Editor select all nodes (A), and in N-panel > Dashboard > Administration click Apply To Selected button.

If the game does not run as expected, also click Force Compile.

Logic tree should look like this:

../../../_images/15_move_object.png

Logic tree for moving an object with keyboard

Run the game, use the keyboard keys we set in first step to move the Cube.

If object is moving in wrong direction, either swap keys in Keyboard Key nodes (i.e. A > D and D > A), or swap A and B inputs in Math node.