I have written below script for the Airplane this script allows airplane to move right or left and up and down but I want air plane to move forward and back also …May I get help for the same…
using UnityEngine;
using System.Collections;
public class MoveAirPlane: MonoBehaviour {
public float _init_x = 0.0f; //inital x position
public float _init_y = 0.0f; //initial y position
public float _horizontal_extent = 20.0f; //max horizontal distance achieved on each side
public float _vertical_extent = 10.0f; //max vertical distance achieve on each side
public float varspeed = 50.0f;
// Use this for initalizing setting
/*void initSettings()
{
}*/
// Use this for initialization
void Start () {
// initSettings();
}
// Update is called once per frame
void Update () {
Quaternion temp_rotate0 = new Quaternion((Input.GetAxis("Vertical") / 4) * -1, 0.0f, (Input.GetAxis("Horizontal") / 4) * -1, 1.0f);
//set the new rotation with a tween so that the craft returns back to normal in a slow motion
transform.rotation = Quaternion.Lerp(transform.rotation, temp_rotate0, 0.05f);
//0.05f will limit the rotation to maximum 45 degrees on each side, 1 will make it 90
transform.position = new Vector3(Mathf.Clamp(transform.position.x, _init_x - _horizontal_extent, _init_x + _horizontal_extent),
Mathf.Clamp(transform.position.y, _init_y - _vertical_extent, _init_y + _vertical_extent), transform.position.z);
transform.Translate(Input.GetAxis("Horizontal") * 50, Input.GetAxis("Vertical") * 50, 0, Space.World);
rigidbody.AddForce(0,0,5 * varspeed);
}
}