How to detect an actor is moving left or right?

guru-at-zidwareguru-at-zidware Member Posts: 369
edited November -1 in Working with GS (Mac)
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

Comments

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    ok, rough idea of how to do it: (thinking as I go). Timers may need tweaking.

    ...

    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...
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Theres a easier way to do it. In the actor you want to detect for the left movement do when attribute self motion linear x is < 0, and then for the right movement when attribute self motion linear x is > 0.

    Cheers
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    yep that seems alot better...(doh!)
  • guru-at-zidwareguru-at-zidware Member Posts: 369
    ok..thanks I will try these...always makes senses when you guys chime in..!

    John
Sign In or Register to comment.