I'm trying to have per-body damping rather than a global value and as far as I can tell, the way to do this is to override each body's "velocity_func". I've done this and pointed it at my own function, which is just a mirror copy of the built-in, default function except I modify the 'damping' parameter at the top of the function.
Code: Select all
void customVelocityUpdate(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{
// Set custom damping value
damping = 0.95;
// Below is the code from the built-in Chipmunk function, verbatim
body->v = cpvclamp(cpvadd(cpvmult(body->v, damping), cpvmult(cpvadd(gravity, cpvmult(body->f, body->m_inv)), dt)), body->v_limit);
cpFloat w_limit = body->w_limit;
body->w = cpfclamp(body->w*damping + body->t*body->i_inv*dt, -w_limit, w_limit);
cpBodySanityCheck(body);
}
Code: Select all
simSpace->damping = 0.95f;
So the questions are:
1. What causes the global 0.95 value to become 0.44 by the time it hits the update function?
2. What do I need to do to duplicate that translation?
3. Doesn't 0.44 seem like a strange number given the 0.95 starting point?
4. Am I correct in that this is how one should override the damping on a per-body basis?
Thanks,
ALF