Tutorial 1: Your first Game Character

In this tutorial you are going to learn how to:

  • Create a game character
  • Apply an external force
  • Link an animation to the game character
  • Implement a simple state-machine
  • Control the character through user-inputs
image1

Overview

We are going to create a subclass of U4DEngine::U4DGameObject. The name of this subclass will be Astronaut and it will inherit all the behaviors of its parent class U4DGameObject.

image

During its initialization, we are going to load rendering information.

image

We are also going to link a walking animation, enable kinetics behavior and set its default state.

image

The Astronaut object will have two states. It will have a walk and an idle state.

image

These states are controlled through the movement of a joystick (mouse). When the user moves the joystick, the state-machine will change the state of the character to a walk state. In this state, the walking animation will be active and an external force will be applied to the character. This force will move the character around the screen.

image

When the user stops moving the joystick, the state-machine will change the state of the character to an idle state. The walking animation will be disabled and all velocities removed.

Source Code

The files for this tutorial can be found here.

Let's begin: