- Home /
How to determine if my plane is facing downards (unityscript)
Hi, I have a plane build, and I want it to accelerate when it faces downwards through unityscript. Using local rotation isnt reliable, since it changes all the time. Is there a way of using global rotation to determine if it is facing downwards?
Answer by Paulius-Liekis · Jul 18, 2012 at 09:55 AM
Global rotation is returned by transform.rotation.
You can check if it's faceing downwards by checking transform.forward.y. It should be: 0 - when plane is leveled and -1 when facing downwards.
Thanks for the quick answer! will it return -1 only if the plane faces EXACTLY downwards or if it starts facing downwards? I want my plane to gain velocity depending on how much it faces downwards
if (transform.forward.y < 0) factor = $$anonymous$$athf.Abs(transform.forward.y);
Yes, factor will be propotional to how much it is facing downwards
Answer by whydoidoit · Jul 18, 2012 at 06:32 PM
Try this:
if(Vector3.Dot(transform.up, Vector3.up) < 0)
{
//Facing downwards
}
This is correct if we're talking about Unity Plane primitive. It is not correct if we're talking about general (air)plane model which is oriented in Z direction.
Yeah comedy answer that I had it checking the Z and then I flipped it when I looked at the title of the questions :)