- Home /
Airplane Control, Aim ... Lerp and Vectors
Hi guys I want to write a airplane controller like ; http://www.youtube.com/watch?v=WobSDjRTLcE : War Thunder MMO .
There is two vector for Mouse (desired location) and Head of Plane (current location, crosshair). When you move mouse, Plane slightly looking to Mouse position. I want to write script like this. But I get some errors. First of all, here is my code;
public Transform aim;
Vector3 from;
Vector3 to;
public float smoothness; //3
public float sensitivity; //1
public float speed; //200
void Start () {
from = aim.position ;
to = from; //starting positions are the same
}
void Update () {
to.x += Input.GetAxisRaw ("Mouse X")*sensitivity;
to.y += Input.GetAxisRaw ("Mouse Y")*sensitivity;
to.z = aim.position.z;
Debug.DrawLine (from, to);
from = Vector3.Slerp(from,to,Time.deltaTime * smoothness);
//'from' always wants to catch 'to'
transform.LookAt (from);
rigidbody.AddRelativeForce (0,0,Input.GetAxisRaw ("Vertical")*speed);
}
Aim transform is Empty game object that front of Plane (at (0,0,7) realative to plane), also, child of my Plane. It works perfectly, if I don't turn plane...
Problem is, I do not change Vector's position relatively. If i change , it will work (I thing ?) because mouse axis input are changing x and y of Vector, but when we turn 90degree to right it doesn't change x and y anymore.
1- How can I change Vector3's axis locally? 2- Do you know the name of technique that using two position to control airplane?
Thanks a lot!!!