...teleport physics objects while keeping velocity

Get help using Construct 2

Post » Wed Aug 08, 2012 9:44 am

I am basically trying to create a portal. I wan't to save the velocity, and restore it after setting the new position.
B
3
Posts: 3
Reputation: 281

Post » Wed Aug 08, 2012 12:34 pm

On the collision with the portal, save the speed and acceleration, change X and Y, restore the speed and acceleration. ^^
ImageImageImageImageImageImage
B
93
S
19
G
12
Posts: 1,192
Reputation: 18,301

Post » Fri Aug 10, 2012 6:07 pm

I tried what you told me, but it didnt work. Well, most of the time, that is. Im guessing there is some kind of race condition.

I tried delaying the call to setVelocity with 10 ticks, and it turned out to work. Out of curiosity, I tuned it down to 3, and the problem was back.

Im not sure how construct 2 uses box2d, but I am guessing that whenever an object is moved, a new box 2d body is created, but it isnt created at once. You have to wait for the next box2d update. And so if you call setVelocity too early, you are setting the velocity on the old body.
B
3
Posts: 3
Reputation: 281

Post » Fri Aug 10, 2012 6:33 pm

Clarify: "it didn't work". What was the result of the experiment that led you to conclude, that "it didn't work."kabuto2022012-08-10 18:34:39
B
5
S
2
G
3
Posts: 36
Reputation: 1,622

Post » Fri Aug 10, 2012 6:37 pm

I think the main thing is that you cant really combine set positioning with physics in c2. It messes up the physics and the delay you said you had to add before itd work is probably from the physics "kicking back in" after directly changing its position
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

Post » Fri Aug 10, 2012 7:58 pm

@aridale is correct. You should destroy the object at the portal and create a new one with its properties, including speed and acceleration. Local variables will be perfect for this.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Aug 10, 2012 7:59 pm

Create variable objects for Velocity/Torque etc. and reapply.

I added an example to the arcade:






Not-so-ninja-edit - The example doesn't use local variables, but you can simply swap the global ones and put the variables within the event instead.

Oh and don't cross the streams!

Overlapping/moving the portals onto the ball causes an explosion of balls haha.JohnnySix2012-08-10 20:02:58
Image
B
27
S
9
G
5
Posts: 487
Reputation: 11,939


Return to How do I....?

Who is online

Users browsing this forum: currypuff, makotto, randomly, Walessio and 23 guests