A gravity probleme with an Airplane Controller


I’m bad at describing and my english isn’t very good as well but i will try :slight_smile:

I scripted a airplane controller for an 2D game and it works very good. I dont use a rigidbody for the airplane, so the gravity does not acs on it. Now i want my airplane to get slower when its flying up and faster when it flys down.

I thought that its possible to find out the angle between the airplane and the horizontal axis and make it faster when the angle is bigger or sometghing like that but i dont know how to script it. I hope you understand what i mean :slight_smile:

Many thanks in advance

If in the image above the vertical axis is Y, the easiest way is to use simple trig:

var angle: float = Mathf.Asin(transform.forward.y)*Mathf.Rad2Deg;

This works because the vector transform.forward has unit length, thus its y component is numerically equal to the sin of the angle. The value returned by Asin is in rads, so to get it in degrees we must multiply by Mathf.Rad2Deg.

NOTE: This code is supposed to be part of the airplane script - it takes the transform.forward direction as the direction the airplane nose is pointing to.