How do I calculate G force

Hi Everyone,

I would like to calculate accurate’ish G forces operation on my flying vehicle.
My world units work like 1 unit = 1 m.

Can I do this in LateUpdate(){ ?

I saw in another answer to calculate acceleration like so,

``````accel = (vel - lastVel) / Time.fixedDeltaTime;
lastVel = vel;
``````

Then might I calculate g force simply like this?

``````gForce = accel / 9.8;
``````

Should I also somehow add angularVelocity to this calculation?

Cheers
Fred

Try this, being `currentVelocity` and `lastFrameVelocity` public floats.

``````currentVelocity=RigidBody.velocity.magnitude;
float Gforce=( currentVelocity- lastFrameVelocity ) / ( Time.deltaTime * Physics.gravity.magnitude );
lastFrameVelocity =currentVelocity;
``````

I tried using a delta of rigidbody.velocity.y over Time.fixedDeltaTime, but could not get it to return anything but zero. I’m not sure if the floating point accuracy was maybe too low.

Eventually resorted to the aerodynamic approach (Load Factor = Lift/Weight), which gave me the desired result. Had to divide the load factor by the gravity acceleration constant to get G-units:

``````//calulate G-force
gForce = (liftY / planeMassKG) / Physics.gravity.magnitude;
if ((gForce < 1) && (gForce > -1)) 	// if wings are not generating a lot of lift
{
if (GetGroundedWheels() >= 1)  // and one or more wheels touch the ground
{
gForce = 1f; // override calculated G value
}
}
``````

GetGroundedWheels() simply counts the number of wheels touching down to cater for low-lift situations when your plane is on the ground. It’s not perfect, but it works well in my bush flying game. The only problem is that it requires semi-realistic lift calculations, which may not always be required for your game.

Hope it helps!

Gerry

Probably you need to use FixedUpdate().
In FixedUpdate you compare the flying vehicle (world) actual position with the last position. You get the velocity in x, y, z. Then you get the acceleration in ms using Time.deltaTime and from that the G. Yes in FixedUpdate is better to also include Time.deltaTime to be shore. Then you need to combine the G vector with the gravity (making a vector sum) to get the final G result.
All of this is a presumption never tested out of my head.