Phase 3 - pick up a ball[]
Goal[]
In this phase we will teach GUS to bow down and pickup a ball.
Preparation[]
GUS can stay and walk.
The enhanced FSM graph[]
There are two new states ball_pickup and ball_standing. The prefix ball shows that this states are related to the object ball.
ball_pickup[]
When the FSM is in the state stand and the key "b" is pressed GUS will perform a transition to the state ball_pickup.
The entry action for state ball_pickup is en-frame1 that restart the current animation.
The state action for state ball_pickup sets the current animation to "GUS_ball_pickup".
When the key "s" is pressed while GUS is in state ball_pickup a transition to the state stand will be performed.
When the property frame is 141 the animation ends. GUS performs a transition from state 'ball_pickup to state ball_stand.
ball_stand[]
The entry action for state ball_stand is en-frame1. This sets the property frame to 1 to restart the current animation.
The state action for state ball_stand sets the current animation to "GUS_walking".
When the property frame is 151 the animation ends. GUS performs a transition from state ball_stand to state ball_stand. This let GUS play the walking animation again.
States[]
The state Ball_pickup[]
A state sensor is required to check for the state ball_pickup.
- Add a property sensor that checks the property state for the value ball_pickup. Call the sensor sStateBall_pickup.
The state Ball_stand[]
A state sensor is required to check for the state ball_stand.
- Add a property sensor that checks the property state for the value ball_stand. Call the sensor sStateBall_stand.
Transitions[]
Stand->Ball_pickup[]
If the key "b" is pressed while GUS is in state stand a transition to the state ball_pickup should be performed.
- Add a keyboard sensor named sB to check for the key b.
- Add an AND controller named cStand->Ball_pickup.
- Connect the sensor sStateStand with controller cStand->Ball_pickup.
- Connect the sensor sB with controller cStand->Ball_pickup.
- Add a property actuator aStateBall_pickup that assigns the value "ball_pickup" to the property state.
- Connect cStand->Ball_pickup with aStateBall_pickup.
- As cStand->Ball_pickup is a transition controller connect it to the actuator aStatechange++.
Ball_pickup->Stand[]
If the key "s" is pressed while GUS is in state ball_pickup a transition to the state stand should be performed.
- Add an AND controller named cBall_pickup->Stand.
- Connect the sensor sStateBall_pickup with controller cBall_pickup->Stand.
- Connect the sensor sS with controller cBall_pickup->Stand.
- Connect cBall_pickup->Stand with aStateStand.
- As cBall_pickup->Stand is a transition controller connect it to the actuator aStatechange++.
Ball_pickup->Ball_stand[]
If the Ball_pickup animation ends (frame 141) a transition to the state ball_stand should be performed.
- Add a property sensor named sFrame141 that checks the property frame to be equal to 141.
- Add an AND controller named cBall_pickup->Ball_stand.
- Connect the sensor sFrame141 with controller cBall_pickup->Ball_stand.
- Connect the sensor sStateBall_pickup with controller cBall_pickup->Ball_stand.
- Add a property actuator aStateBall_stand that assigns the value "ball_stand" to the property state.
- Connect cBall_pickup->Ball_stand with aStateBall_stand.
- As cBall_pickup->Ball_stand is a transition controller connect it to the actuator aStatechange++.
Ball_stand->Ball_stand[]
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 Ball_stand to Ball_stand.
- Add an AND controller named cBall_stand->Ball_stand.
- Connect the sensor sStateBall_stand with controller cBall_stand->Ball_stand.
- Connect the sensor sFrame151 with the controller cBall_stand->Ball_stand.
- As cBall_stand->Ball_stand is a transition controller connect it to the actuator aStatechange++.
- Optional: Connect cBall_stand->Ball_stand with aStateBall_stand.
Remarks: There is currently no transition back to stand. This transition will be added in a later phase.
Actions[]
Entry Actions[]
Ball_pickup[]
When entering the state ball_pickup the animation should be reset to frame 1.
- Add an AND controller cEn-Ball_pickup.
- Connect the sensor sStatechanged with the controller cEn-Ball_pickup.
- Connect the sensor sStateBall_pickup with the controller cEn-Ball_pickup.
- Connect cEn-Ball_pickup with the actuator aFrame1
Ball_standing[]
When entering the state ball_standing the animation should be reset to frame 1.
- Add an AND controller cEn-Ball_standing.
- Connect the sensor sStatechanged with the controller cEn-Ball_standing.
- Connect the sensor sStateBall_pickup with the controller cEn-Ball_standing.
- Connect cEn-Ball_standing with the actuator aFrame1
State Actions[]
State action Ball_pickup[]
GUS should play its pickup animation "st-act:GUS_ball_pickup".
- Add an AND controller with the name cBall_pickup.
- Connect the sensor sStateBall_pickup with the controller cBall_pickup.
- Add an action actuator named aBall_pickup. Select the action type "Property". Enter GUS_ball_pickup in the field "AC:" and frame in the field "Prop:".
- Connect the controller cBall_pickup with aBall_pickup.
State action Ball_stand[]
GUS should play its pickup animation "st-act:GUS_ball_standing".
- Add an AND controller with the name cBall_stand.
- Connect the sensor sStateBall_stand with the controller cBall_stand.
- Add an action actuator named aBall_standing. Select the action type "Property". Enter GUS_ball_standing in the field "AC:" and frame in the field "Prop:".
- Connect the controller cBall_stand with aBall_standing.
Cleanup[]
As in the previous phases the logic bricks should be sorted a bit to provide a better overview.
GUS can now walk, stand, pickup and walk while carrying a ball. Unfortunatly there is no ball to carry. The next phase will show how to add the ball.
Proceed with Phase 4 - grap the ball