...teleport physics objects while keeping velocity

0 favourites
  • 7 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • I am basically trying to create a portal. I wan't to save the velocity, and restore it after setting the new position.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • On the collision with the portal, save the speed and acceleration, change X and Y, restore the speed and acceleration. ^^

  • I tried what you told me, but it didn�t work. Well, most of the time, that is. I�m 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.

    I�m 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 isn�t 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.

  • Clarify: "it didn't work". What was the result of the experiment that led you to conclude, that "it didn't work."

  • 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

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)