Trying to get a "semi" realistic aircraft simulator. I'm pulling my hair out because I just can't get the math right. I'm not looking for super realistic but want to at least get some effects like planes increasing speed as their nose is down and being able to stay in flight.
Pseudocode below from my calculateForces method
// All uses of X are different constants
force = new Vector(0,0,0)
airPlaneYaw = plane.rotation.x;
airPlanePitch = plane.rotation.y;
airPlaneRoll = plane.rotation.z;
velocityDirection = plane.velocity.normalize();
airPlaneNoseDirection = plane.getWorldDirection();
airPlaneSurfaceAgainstDirectionOfMotion = airPlaneNoseDirection.angleTo(velocityDirection)
airPlaneSpeed = plane.velocity.length();
drag = X*(speed**2) * sin(airPlaneSurfaceAgainstDirectionOfMotion); // I have a feeling this is wrong
thrust = X;
lift = X * (speed**2) * sin(airPlaneYaw); // I have a feeling this is wrong?
gravity = X;
force.add(velocityDirection.multiply(drag));
force.add(airPlaneNoseDirection.multiply(thrust);
force.add(Vector(0,lift,0);
force.add(Vector(0,gravity,0);
velocity.add(force);
Is this the right model for approaching this? Is my math incorrect? Am I missing any forces?
My plane seems to lose speed when turning even if thrust is constant and ends up falling down. Is that expected in real life? Very annoying in my game because the plane becomes harder to control. Do planes add thrust when turning? Also the plane seems to gain airspeed when nose is down.
planerefers to aTransformcomponent, but we can readily see that's not the case:Transformdoes not have a.velocityproperty or field or a.getWorldDirection()method. For K2xL: it would help to mention the context and coordinate system you're building this in, and how the behaviour of this code differs from what you want. \$\endgroup\$