Original Post
I recently read an article on Verlet integration (http://lol.zoy.org/b...motion-in-games) and wanted to apply it. It seems to work, but I'm not sure how to use it with my collision detection code. My update function looks something like this:
[source lang="cpp"]void State::Update(float dt)
{
Vector accel = Vector(...) //get accelreation based on user input
Vector oldVel = vel;
vel += (accel) * dt;
pos += (oldVel + vel) * 0.5 * dt;
if( if_collision_is_enabled )
{
Vector newpos = CollideWithWorld(pos,vel); //get new position
//update velocity & position based on the new position
vel = newpos - pos;
pos = newpos;
}
}[/source]
It seems to work, but the movement isnt as smooth as it is without collision. I assume I'm not updating the velocity and position correctly after the collision. Does anyone know a better way to do this?
[source lang="cpp"]void State::Update(float dt)
{
Vector accel = Vector(...) //get accelreation based on user input
Vector oldVel = vel;
vel += (accel) * dt;
pos += (oldVel + vel) * 0.5 * dt;
if( if_collision_is_enabled )
{
Vector newpos = CollideWithWorld(pos,vel); //get new position
//update velocity & position based on the new position
vel = newpos - pos;
pos = newpos;
}
}[/source]
It seems to work, but the movement isnt as smooth as it is without collision. I assume I'm not updating the velocity and position correctly after the collision. Does anyone know a better way to do this?