Move a specific distance

jamie_cjamie_c ImagineLabs.rocksMember, PRO Posts: 5,772
edited November -1 in Working with GS (Mac)
Hi All,

I'm new to gamesalad and have probably a pretty basic question. How would I make a character move a specific distance when a key is pressed?

For example I've look at the How Tos and done some of the movement stuff so I can move a character smoothly around the screen by following some of the information there.

But what I really want is this kind of movement.

If I press the 'up' arrow once I want my character to move exactly 100 pixels up the screen and stop.

Then if I press the 'left' arrow I want the character to move exactly 100 pixels to the left, etc.

I don't want the character to jump to the new spot, but move/slide to it.

Thanks in advance.
Jamie

Comments

  • outasiteoutasite Member Posts: 417
    If your character is moveable, use "MOVE TO"
    >>position.x + 100 for moving right
    >>position.x - 100 for moving left
    >>position.y + 100 for moving up
    >>position.y - 100 for moving down

    If your character is n0n-moveable, use "INTERPOLATE"
    >>position.x + 100 for moving right
    >>position.x - 100 for moving left
    >>position.y + 100 for moving up
    >>position.y - 100 for moving down
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Thanks, I'll give this a try.

    Jamie
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    I tried the code outlined above and it does now work as expected.

    I've created a 100x100 square actor and applied the Move To behavior when you press the Up key. The actor does move up but never stops, it just continues off screen, what am I doing wrong?

    Here is a screen-grab of the short script attached to the actor.

    http://www.clay-communications.com/help.png

    Thanks
    Jamie
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    I would go with interpolate, but the way he posted above wont work because you cant interpolate + or - a number as the value is constantly changing when the interpolate is happening.

    This is how i would do it:

    Make a real attribute called moveDestination (or whatever you want to call it)

    make a rule when key up is down
    -change attribute moveDestination to self position y+100
    -interpolate self position y to moveDestination

    make a rule when key down is down
    -change attribute moveDestination to self position y-100
    -interpolate self position y to moveDestination

    make a rule when key left is down
    -change attribute moveDestination to self position x-100
    -interpolate self position x to moveDestination

    make a rule when key right is pressed
    -change attribute moveDestination to self position x+100
    -interpolate self position x to moveDestination
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Okay, gonna give that a try next.

    Thanks for the advice.
    Jamie
Sign In or Register to comment.