detecting g force

hi there

I want to do a ‘blackout’ feeling on a plane. The usual thing you see that everything goes black or white when you are turning at very high Gs during a certain amount of time.

I have some ideas in mind but none seem to work good enough. Anyone knows how’s possible to achieve this on unity?

The black/white thing is easy, just a texture with alpha. What I’m wondering is how to detect when it should be called and with what strength.

I too would like to detect force but not sure how? So… BUMP!

In games this is one of the hardest things to do realistically.

The hardest part is you need to calculate acceleration/force which is something that you really need to be fed samples at a fixed time rate to do properly. if your framerate drops and your doing this in Update you’ll be SOL.

http://www2.franciscan.edu/academic/MathSci/MathScienceIntegation/MathScienceIntegation-836.htm

what that means in game terms is

( currentVelocityXYZ - lastFramesVelocityXYZ ) / Time.deltaTime

So if you were using rigid bodies you would save off the frames rigidbody.velocity and in the next frame us it to detect the change in velocity above and then afterwards storing it again.

Keep in mind its dangerous to divid by Time.deltaTime because it can be set to zero in pause situations.

Now that will get you acceleration if you want it to be in G’s ( which is gravity units of force ) you would get the magnitude of gravity and do something like this:

( currentVelocityXYZ - lastFramesVelocityXYZ ) / ( Time.deltaTime * Physics.gravity.magnitude )

If your not using rigid bodies at all, you need to calculate velocity as well which will make things even more unstable:

( currentPositionXYZ - lastFramesPositionXYZ ) / ( Time.deltaTime )

Anyways unless you do this work in FixedUpdate or you roll your own catch-up style physics you’ll get really bad physics if you plan on moving stuff by the accelerations or velocitys calculated.

2 Likes