I'm working on a very small 2d sidescroller-type flying game. Last few days I've been trying to simulate lift and drag with Chipmunk with no luck. I've looked through various resources on the internet dealing with drag and lift but still couldn't implement it correctly.
I'm having a simple cpBody with some initial impulse force applied for speed. This is how I'm trying to calculate lift and drag (every frame):
Code: Select all
float lift = -airDensity * speed*speed * attackAngle * liftCoefficient;
float drag = -airDensity * speed*speed * attackAngle*attackAngle * dragCoefficient;
Code: Select all
float airDensity=1.29;
float speed=cpvlength(airplaneBodyVelocity);
float velocityAngle=-atan2(airplaneBodyVelocity.y,airplaneBodyVelocityy.x);
float attackAngle=bodyAngle-velocityAngle; //attack angle is difference between velocity and current angle set by player
float liftCoefficient=1.0;
float dragCoefficient=1.0;
float lift = -airDensity * speed*speed * attackAngle * liftCoefficient;
float drag = -airDensity * speed*speed * attackAngle*attackAngle * dragCoefficient;
cpVect;
forceVector.x=drag;
forceVector.y=lift;
cpBodyResetForces(airplaneBody);
cpBodyApplyForce(airplaneBody, forceVector, cpvzero);