Glider Physics (Engine)

Hello all,

I want to build a simulation of a glider and am wondering if you think the physics engine can provide a reasonably accurate prediction? It is for an educational application so it is kind of important that it reflect reality (again reasonably).

This particular glider is launched in much the same way as a slingshot, so I think the following thread provides an excellent start …

http://answers.unity3d.com/questions/120661/2d-gliding-physics.html

My thought is that a glider launched in this way should largely behave similarly to a projectile, but obviously there will be lift and drag applied at the wing and tail position (which I can add using AddForceAtPosition??). The magnitude of these lift and drag forces will depend on the angle of the force (angle of attack) which will be changing throughout the simulation.

The lift forces acting on the tail and wing will cause the plane to want to rotate about its center of gravity. I am assuming / hoping that the physics engine can capture this rotation and perform the lift calculations (based on the angle produced by this rotation) and just keep things rolling until the plane lands on the ground …

So can the physics engine handle this? Any advice from you physics (engine) buffs?

Thanks!

EDITED: Thanks Aldonetto! This is a huge help!

Just a couple more silly questions (sorry but the physics engine is a new beast to me):

  1. units (mass) - I read somewhere that mass was in kg, so I am using a mass of 0.01 (about 10g for a balsa glider). Sound right?

  2. units (force) - what are the units in force - Newtons?

  3. I can apply an initial force (using AddForce with ForceMode.Impulse) - currently using 1.4 assuming Newtons are the units, or as you suggest I could use an initial velocity. But if go the velocity route, how do I ensure that this is applied in the first frame only (i.e. analogous to ForceMode.Impulse)

Thanks!

The physics engine handles ballistic trajectories very well: just launch the glider by setting its rigidbody.velocity to some suitable value and direction, and it will follow a perfect ballistic trajectory. I suppose it will not automatically align its nose to the trajectory direction, what can be forced with this simple code:

function FixedUpdate(){
    transform.forward = rigidbody.velocity.normalized;
}

This would produce a very decent ballistic flight, but to have something more consistent with a glider behaviour you should replace this code with evaluations of the lift and drag forces. You could use the rigidbody.velocity and transform.forward vectors to calculate these forces, and AddForceAtPosition to apply them (as you suspected). But AddForceAtPosition expects a world point, thus you must define the local position and convert it to world coordinates using transform.TransformPoint.

The idea is something like this:

var tailPoint = Vector3(0, 0, -1.5); // tail position relative to the glider pivot
var wingPoint = Vector3(0, 0.1, 0.2); // wing relative position

function CalcTailForce(): Vector3 {
  // calculate the tail force vector with direction and magnitude based on the
  // angle between rigidbody.velocity and transform.forward
  return force;
}

function CalcLiftForce(): Vector3 {
  // calculate the lift force magnitude based on the angle (in the vertical plane)
  // between rigidbody.velocity and transform.forward
  return force * transform.up; // the lift direction is always the local UP
}

function FixedUpdate(){
  var tailForce = CalcTailForce();
  // apply the force to the tail point
  rigidbody.AddForceAtPosition(tailForce, transform.TransformPoint(tailPoint));
  var liftForce = CalcLiftForce();
  // apply the lift force to the wing point
  rigidbody.AddForceAtPosition(liftForce, transform.TransformPoint(wingPoint));
}

I don’t know exactly how to calculate these forces, and guess you’ll have a hard time tweaking the equations to have a stable flight, but I believe the basic idea can work.

EDITED: About questions 1 and 2: yes, Unity uses the MKS system, thus mass is in Kg, and force in Newtons. The 0.01 mass is too low for the standard settings; you probably will have to reduce rigidbody.sleepVelocity to be compatible with such small object - the default value is 0.15, what means that below 15cm/s physics will place the rigidbody in sleep mode (the glider just gets stuck in the air!).

About question 3, the force/velocity dilemma: you usually will launch the glider with a code like this:

function Update(){
  if (Input.GetKeyDown("some key")){
    // use the velocity approach:
    rigidbody.velocity = launchVelocity * transform.forward;
    // or the force approach:
    rigidbody.AddForce(launchForce * transform.forward, ForceMode.Impulse);
  }
}

Both will have the same final effect: set the rigidbody velocity. With AddForce, physics calculates the resultant velocity after one physics cycle (20mS) of continuous acceleration, what means that the glider mass and the force intensity are taken into account: 1.4N applied to 0.01Kg mass gives an acceleration of 140m/s2, which during 20mS results in 2.8m/s. The velocity approach is simpler - just assign a 2.8m/s speed - but in your case the force approach may be better, since it will show the individual influence of force and mass in the glider flight.