This project has moved and is read-only. For the latest updates, please go here.

Estimate body position after several timesteps

Aug 7, 2011 at 8:55 PM
Edited Aug 8, 2011 at 12:19 AM

User/player body is at position up1 at timestamp t1. AI player body is at position ap1 at t1.

Lets say timestamp t2 = t1 + 5 * deltaTimeStep -> after 5 World.Step calls.

AI player/body has to reach/block the user player/body after 5 timesteps (at t2). I have to compute LinearImpulse for the AI player so it will move to position up2 at timestamp t2.  

The enemy body (user player) has its linear velocity, damping , friction and it is bouncing off walls. 

Right now I am just doing simple up2 = up1 + linearvelocity * 5 timesteps. Then I use Impulse = Mass * Velocity where mass is AI player mass and velocity = (up2 - ap1) / 5*timesteps i.e. displacement vector from user projected position to AI player current position divided by the time i want the ai player to reach the user player.

It works but not too well, especially cuz I am not catering for both AI/user body damping, and bouncing from world boundaries.

Any suggestions?

It would have been super if I could call the World.Step(deltaT) 5 times since it will move all the bodies according to all physics and if there was a way to restore the world back to the place where is started simulating, i would be able to just use World.Step to estimate the new position and then restore the world back.

sort of lost right now.

Aug 8, 2011 at 10:47 AM

Could you clone all your non-player plysics objects (walls, maving surfaces, etc...) into a new world instance (and if you can, do this once at the beginning of the level). This simulation would only have the player in it (no enemies).

You can advance the 'player-only' wold by however far you like, and then you have your answer as to where he will be (if no enemies bounce him about - which is what I assume you're after). Each time you want to predict the player's path, copy all the simulation variables (position, linearvelocity, angularvelocity, etc...) from the 'real' world into the cloned 'player-only' world, and run the simulation there.