[Solved]How do I move an object between 3 different points?

Get help using Construct 2

Post » Wed Aug 05, 2015 10:59 pm

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!
Last edited by Modsnush on Fri Aug 07, 2015 4:38 pm, edited 1 time in total.
B
4
Posts: 16
Reputation: 214

Post » Thu Aug 06, 2015 1:17 am

Modsnush wrote: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:

Code: Select all
Function Update_Object_position
Pick Location.Index = Object.Position
Set Object.X/Y to Location.X/Y


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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Thu Aug 06, 2015 1:00 pm

Thanks alot for taking the time to answer! This looks like a logical way to do it.
I will try to figure this out as soon as I get home from work!
B
4
Posts: 16
Reputation: 214

Post » Thu Aug 06, 2015 2:46 pm

B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Fri Aug 07, 2015 10:38 am

Hey thanks alot, this is almost the behavior I am looking for! This really helps me understand the logic behind it.
How would I go about making them snap to the locations instantly instead of the bullet speed though?
I tried implimenting @Nimos100 solution and looking at yours as a reference as to how things are set up, but I can't get it to work


Forum had some problems so I couldn't post any reply. Seems to be working now!
B
4
Posts: 16
Reputation: 214

Post » Fri Aug 07, 2015 11:24 am

Modsnush wrote:Hey thanks alot, this is almost the behavior I am looking for! This really helps me understand the logic behind it.
How would I go about making them snap to the locations instantly instead of the bullet speed though?
I tried implimenting @Nimos100 solution and looking at yours as a reference as to how things are set up, but I can't get it to work


Forum had some problems so I couldn't post any reply. Seems to be working now!

The idea I posted doesn't use bullet behaviour, it just moves the object to another object position. You could do it without and just change the coordinate (X,Y) to where you want your object to go to. But using 3 small sprites and just move the object to one of those depending on the index, you can move them around screen and the object will always go to the correct position. So its simply so you can make the functionality one time and then you don't have to keep updating the X,Y whenever you want to move them. If you want it to move instantly as I understand you want, you don't need the bullet behaviour, think that will only mess things up.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Fri Aug 07, 2015 11:48 am

No I know, the one @mrcgkh provided is with the bullet behavior though and it's not entirely what I'm looking for. It should only set the coordinate like the solution you provided so I'm trying to do that now though I'm not sure how I go about making the function you provided.

Thanks for your help, I will read up some more in the manual and try again with your solution.
B
4
Posts: 16
Reputation: 214

Post » Fri Aug 07, 2015 1:19 pm

@Modsnush if you want a instant move it will be easier
https://drive.google.com/file/d/0BzXd1GMzUo9HZDUtd1JTUExXRUE/view?usp=sharing
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Fri Aug 07, 2015 4:32 pm

@mrcgkh Hey thanks alot, this is exactly what I'm looking for. You didn't have to do it for me though but I really appreciate it!

Cheers!
B
4
Posts: 16
Reputation: 214

Post » Fri Aug 07, 2015 8:12 pm

@Modnush
Sometimes Arrays can be confusing. Here's a non-array version
https://drive.google.com/file/d/0BzXd1GMzUo9Ha0ZZM0Y5ckdPUWc/view?usp=sharing
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Next

Return to How do I....?

Who is online

Users browsing this forum: Fenix18, oOScuByOo, tarek2 and 64 guests