- Home /
A gravity probleme with an Airplane Controller
Hey,
I'm bad at describing and my english isn't very good as well but i will try :)
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 :)
Many thanks in advance
Answer by aldonaletto · Oct 18, 2011 at 01:42 PM
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.