unfortunately it seems I'm making another post right on top of my other one, sorry about that.
I was wondering why the velocity limit (v_limit) for an object is only given a single value limit in X and Y. Inside cpBodyUpdateVelocity:
Code: Select all
body->v = cpvclamp(cpvadd(cpvmult(body->v, damping), cpvmult(cpvadd(gravity, cpvmult(body->f, body->m_inv)), dt)), body->v_limit);
Code: Select all
cpVect calcVel = cpvadd( cpvmult(body->v, damping), cpvmult(cpvadd(gravity, cpvmult(body->f, body->m_inv)), dt) ); //Calcs
cpVect horizVec = cpvclamp(cpv(calcVel.x,0.0),50.0f); // Clamp just the X
cpVect vertVec = cpvclamp(cpv(0.0,calcVel.y),10.0f); // Clamp just the Y
body->v = cpv(horizVec.x,vertVec.y); // set new body velocity to clamped X and Y
So really my questions are:
1) Is there an actual way of doing this that I have missed?
2) If there isn't, I'm sure there is a good reason and I am nosey enough to ask what it is haha
I am using C++ so I am trying to keep everything as OO as possible, so function pointers are a pain for me personally in this instance. Making my code above OO (i.e. being able to specify my own MaxX and MaxY per object) seems awkward so I was hoping for any words of wisdom you may have =).
There is always the icky option of inheriting off the cpBody struct and adding the variable myself (I could also add a flag to turn gravity on/off while I was at it) but... not very nice I think.
Cheers,
Adam