GameBlender 4 Ever
Advertisement

Phase 2 - walking on place[]

Goal[]

In this phase we will learn how to improve the FSM graph to let GUS walk. The examples will demonstrate a way to translate the FSM graph to logic bricks.

Preparation[]

Now GUS is standing around playing his idle animation.

The FSM graph enhanced with state walk[]

Additional to the FSM graph from phase 1:

When the FSM is in the state stand and the key "s" is pressed GUS will perform a transition to the state walk.

The entry action for state walk is en-frame1. As before this sets the property frame to 1 to restart the current animation.

The state action for state walk sets the current animation to "GUS_walking".

When the property frame is 41 the animation ends. GUS performs a transition from state walk to state walk. This let GUS play the walking animation again.

When the key "w" is pressed while GUS is in walking state a transition to the state stand will be performed.


Fsm phase2 walk


States[]

The state Walk[]

Another state sensor is required to check for the state walk.

  • Add a property sensor that checks the property state for the value walk. Call the sensor sStateWalk.

FSM phase2 state walk

Transitions[]

Stand->Walk[]

If the key "w" is pressed while GUS is in state stand a transition to the state walk should be performed.

  • Add a keyboard sensor named sW to check for the key w.
  • Add an AND controller named cStand->Walk.
  • Connect the sensor sStateStand with controller cStand->Walk.
  • Connect the sensor sW with controller cStand->Walk.
  • Add a property actuator aStateWalk that assigns the value "walk" to the property state.
  • Connect cStand->Walk with aStateWalk.
  • As cStand->Walk is a transition controller connect it to the actuator aStatechange++.

FSM phase2 transition stand walk

Walk->Walk[]

As the walking animation will come to an end (at frame 41) we need to restart the walking animation. This will be done by a transition from state walk to walk.


  • Add a property sensor named sFrame41 that checks the property frame to be equal to 41.
  • Add an AND controller named cWalk->Walk.
  • Connect the sensor sStateWalk with controller cWalk->Walk.
  • Connect the sensor sFrame41 with the controller cWalk->Walk.
  • As cWalk->Walk is a transition controller connect it to the actuator aStatechange++.
  • Optional: Connect cWalk->Walk with aStateWalk .

FSM phase2 transition walk walk

Walk->Stand[]

If the key "s" is pressed while GUS is in state walk a transition to the state stand should be performed.

  • Add a keyboard sensor named sS to check for the key s.
  • Add an AND controller named cWalk->Stand.
  • Connect the sensor sStateWalk with controller cWalk->Stand.
  • Connect the sensor sS with controller cWalk->Stand.
  • Connect cWalk->Stand with aStateStand.
  • As cWalk->Stand is a transition controller connect it to the actuator aStatechange++.

FSM phase2 transition walk stand

Actions[]

Entry Action[]

When entering the state walk the animation should be reset to 1. This will be done as before in state stand be setting the property frame to 1.


  • Add an AND controller cEn-Walk.
  • Connect the sensor sStatechanged with the controller cEn-Walk.
  • Connect the sensor sStateWalk with the controller cEn-Walk.
  • Connect cEn-Walk with the actuator aFrame1

FSM phase2 En-WalkAction

State Action[]

GUS should play its walking animation "st-act:GUS_walking".

  • Add an AND controller with the name cWalk.
  • Connect the sensor sStateWalk with the controller cWalk.
  • Add an action actuator named aWalking. Select the action type "Property". Enter GUS_walking in the field "AC:" and frame in the field "Prop:".
  • Connect the controller cWalk with aWalking.

As the walking and the standing animation do not have a smooth blending it is recommended to switch Blenders animation blending on.

  • Switch on animation blending for the action actuator aWalking by setting the parameter Blendin to 5.
  • Switch on animation blending for the action actuator aStanding by setting the parameter Blendin to 5.

FSM phase2 WalkAction


Cleanup[]

As in phase 1 the logic bricks should be sorted a little bit to provide a better overview.

FSM phase2 cleanup


GUS can now walk and stand. Both states look quite similar and they are. This makes it easy to add other states as they follow the same logic. Now proceed with Phase 3 - pick up a ball or go back to FSM with logic bricks

Advertisement