- Home /
fly speed , increasing speed
hello everyone,i'm trying to use SacFree flight script ,and i have this script attached to cube,and i have camera attached to cube too, i can fly in the same speed but i want to increase my speed while i'm going down. And i tried something to do this: when i'm going straight i looked to my Rotation X and it was around +5 , and when i started flying down my rotation x was more than for example 15 ( here what i mean : http://ressim.net/s/upload/7f79072b.png )
so i tried something like this:
if (transform.rotation.x > 15) {
print("you are going down "); }
but nothing was written on the console, which if statement need i use to do this. Please help.
And here is the script, also what should i use to increase my speed in the right if statement. ( note speed increases when i increase acceleration and max speed )
var YawSpeed = 30.0; var TurnSpeed = 30.0; var ElevateSpeed = 16; var Acceleration = 30; var MaxSpeed = 120; private var Speed = 0.0;
function Update(){
if(Speed >= MaxSpeed){Speed=MaxSpeed;}
if(Speed <= (MaxSpeed / 3)){ rigidbody.useGravity = true; }else{rigidbody.useGravity = false;}
transform.Translate(Vector3.forward Speed Time.deltaTime);
if(Input.GetAxis("Accelerate")){Speed = Speed + Acceleration;} if(Input.GetAxis("Decelerate")){Speed = Speed - Acceleration;}
transform.Rotate(0,Input.GetAxis("Yaw") YawSpeed Time.deltaTime,0); transform.Rotate(0,0,Input.GetAxis("Turn") TurnSpeed Time.deltaTime); transform.Rotate(Input.GetAxis("Elevate") * ElevateSpeed 2 Time.deltaTime,0,0);
if (transform.rotation.x > 20) {
print("you are going down "); }
}
Answer by Antony-Blackett · May 15, 2011 at 01:44 AM
transform.rotation.x gets the X component of the Quaternion which is not what you want, see http://unity3d.com/support/documentation/ScriptReference/Quaternion.html. You want the x axis rotation in euler angles. Do this instead.
if( transform.rotation.eulerAngles.x > 20 )
{
print("you are going down ");
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613134226im_/https://answers.unity.com/themes/thub/images/avi.jpg)