1
\$\begingroup\$

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.

\$\endgroup\$
10
  • \$\begingroup\$ And, I think lift force should't be vertical. If so you will not get planes increasing speed as their nose is down. See LiftForce. \$\endgroup\$
    – Mangata
    May 7, 2022 at 7:22
  • 1
    \$\begingroup\$ @Mangata that would be accurate if we knew that this question was in the context of the Unity game engine and that plane refers to a Transform component, but we can readily see that's not the case: Transform does not have a .velocity property 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\$
    – DMGregory
    May 7, 2022 at 12:51
  • \$\begingroup\$ Working with threejs if that context helps. Will edit question with more details of behavior \$\endgroup\$
    – K2xL
    May 7, 2022 at 22:38
  • \$\begingroup\$ @Mangata How should lift force be applied? Should it be angle of the aircraft or should it be something else? For reference, i found this from NASA which I interpreted lift as a vertical force wright.nasa.gov/airplane/lifteq.html \$\endgroup\$
    – K2xL
    May 8, 2022 at 0:10
  • \$\begingroup\$ A fluid flowing around an object exerts a force on it. Lift is the component of this force that is perpendicular to the oncoming flow direction. Lift_(force) \$\endgroup\$
    – Mangata
    May 9, 2022 at 3:29

0

You must log in to answer this question.

Browse other questions tagged .