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