I'm trying to get a camera to smoothly follow my RigidBody but get a strange jittering effect. (Not my video, but it looks similar to this: http://www.youtube.com/watch?v=_3R_8xJ7-rE)
So I've tried two things.
Thing one: Updating the camera using the physics time step.
Code: Select all
function updateWorld() // uses framerate independant fixed timestep
{
var currentTime = getCurrentTime();
var delta = currentTime - lastTime;
lastTime = currenTime;
applyForces(delta)
world.stepSimulation(delta, 100, 0.1)
updateCamera(delta)
}
So when I press PrintScreen the RigidBody will move forward more than a normal frame because of the increased delta time. Then, when I update the camera, it is further behind than it was so it jerks forwards to try and compensate. I can affect the speed of this "jerk" by changing the damping constants of my spring.
However, this really isn't good enough so I tried:
Thing two: Updating the camera in the fixed time step.
Code: Select all
world.setInternalTickCallback(postSubStepTick, null, false);
function postSubStepTick(world, t)
{
updateCamera(t);
}
function updateWorld() // uses framerate independant fixed timestep
{
var currentTime = getCurrentTime();
var delta = currentTime - lastTime;
lastTime = currenTime;
applyForces(delta)
world.stepSimulation(delta, 100, 0.1)
}
When I added up all the values of "t" in postSubStepTick, these fell short of the timestep fDelta, instead this seems to get fired for each internal tick callback.
I've looked around a fair bit for an answer to this, but I can't find anything that helps. I'm not sure which direction to go in, so any help / experience would be greatly appreciated!
Thanks,
John