How to detect an actor is moving left or right?
guru-at-zidware
Member Posts: 369
Hi..
I want to change an animation state by detecting if the actor is moving left or right. Any good methods for doing this? Thanks!
John
I want to change an animation state by detecting if the actor is moving left or right. Any good methods for doing this? Thanks!
John
Comments
...
make a game attribute...'game.actor_old_position_x'
make a game attribute.. 'game.actor.walking_direction' (Lets say: 0 = left, 1 = still, 2 = right)
...
timer set so every 0.4 seconds:
Change attribute 'game.actor_old_position x' to 'actors x position'
another timer:
every 0.01 seconds
Rule:
If 'actors x position' < 'game.actor_old_position x'
Change Attribute 'game.actor.walking_direction' to '0'
If 'actors x position' = 'game.actor_old_position x'
Change Attribute 'game.actor.walking_direction' to '1'
If 'actors x position' > 'game.actor_old_position x'
Change Attribute 'game.actor.walking_direction' to '2'
...
Then have animation rules set up so if 'game.actor.walking_direction'
= '0' play walking left animation
= '1' play standing idle animation
= '2' play walking right animation
...
Hope that makes some sort of sense...good luck.
(You might get problems where the timer resets the 'old position' every 0.4 second and for 0.01 second Gamesalad wants to display the standing idle animation, but it might not notice...or tweak the rules, so it plays the appropriate animation after 0.2 seconds. So it will only play that animation if your character is definately going in that direction, or definately standing still)
note: never actually done a platformer/walking game, but this should hopefully be about right...
Cheers
John