Precise stopping

Get help using Construct 2

Post » Thu Jan 17, 2013 12:30 pm

Hi
I need a character that uses either the platform behavior or Bullet Behavior to stop precisely when it's x position lines up with that of the object it's overlapping.Does anyone know how I can achieve this?, just testing if the objects x positions are the same doesn't work.
any help would be appreciated
thanks
B
5
S
1
G
1
Posts: 52
Reputation: 1,222

Post » Thu Jan 17, 2013 3:24 pm

Simply texting for the x position to be the same is unlikely to work because Construct can only test an object's position so many times per tick and moves objects multiple pixels at once.

I see two main solutions for this.

Probably the more elegant one is to, once it's overlapping, predict when it's going to cross the next tick using dt (there's more information on that if you search the manual). dt times its speed X vector will give you the number of pixels it will move on the next tick. With this you can then test it's approach from the left side using if ((stopper.X - bullet.X) < (bullet.VectorX*dt) and stopper.X > bullet.X), with another modified expression for if the object is approaching from the other side (stopper.X < bullet.X). If true you then set its speed to 0 and use set X to put it in exactly the right place.

If you're really not comfortable with expressions (though I suggest you do get comfortable with them at some point), another solution would be to create two new invisible objects 1 pixel wide that mark the left and right sides of the stopping object. When the bullet collides with the invisible objects with the correct trajectory (VectorX < 0 for the left one and VectorX > 0 for the second one) you then force the bullet into the precise position (with set position X) and set its speed to 0.

I hope this helps!Phyvo2013-01-17 15:26:06
B
6
S
1
Posts: 40
Reputation: 917

Post » Thu Jan 17, 2013 3:39 pm

I myself just use 'compare two values', with value one the distance between the player and the object, then check if it is less then a really small number (I use 4 and it will consistently detect, but it may need to be larger if your objects move fast/are large).

And that's it! There is no way my eyes could ever tell that the player is 1-3 pixels off centre, but if it really matters, make the first action 'set player position to object'. So this way, when it gets within 4 pixels, the player will centre itself on the object.
B
27
S
8
G
5
Posts: 429
Reputation: 6,902

Post » Thu Jan 17, 2013 10:37 pm

I second tobye suggestion. check for "greater than or equal to" and then snap it back to exactly where you want it right afterwards with a "set position" action, visually you shouldn't see that pop.

B
50
S
21
G
8
Posts: 844
Reputation: 10,299


Return to How do I....?

Who is online

Users browsing this forum: Braus and 15 guests