So I'm struggling with this. I want an object to move between 3 different points on the X axis, like this: * * *
The object starts in the middle, then if I press the left arrow key it will snap to the left point. If i press the right arrow key it will snap to the middle and if i press right again it will snap to the right and vice versa. It's a simple mechanic but I'm struggling to make this work properly. I tried using the MoveTo plugin by REX and it works between 2 points but I can't for the life of me, figure out how to make it work seamlessly between 3 points. I have no idea what the best pracises are for these kinds of mechanics.. Any help is greatly appreciated!
There are lots of ways to do this, but the easiest might be to simply make a variable in your object called "Position" or something. This variable then hold the current position of the object. Like so:
(X = 1) (X = 2) (X = 3)
Then in your object you simply check what value the position is, when you press a key and add or subtract based on the key pressed.
So if the object starts in the middle the "Position" variable is 2. Pressing Left key you subtract 1 from Position and if its the Right key you add 1.
Then you can make 1 small sprite object (Named location) and give it an index variable and make 3 instances of it, each with a different index that relate to the position, so it would be 1 for the left one, 2 for the middle and 3 for the right one, then you can use those to easily control the position of the object, and so you can move it around later if you need to without having to change any code.
And then you add something like this:
Function Update_Object_position
Pick Location.Index = Object.Position
Set Object.X/Y to Location.X/Y
[/code:1h4ielcw]
Then you ofc just have to add the keys to add and subtract from object.position and make sure that position cant go below 1 or above 3, and call the function each time one of the keys are pressed.