Move a specific distance
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
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
>>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
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
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
Thanks for the advice.
Jamie
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page