I am making a game which the player it is a Helicopter which moves in the vertical plane x, y (not horizontal). I have made the basic movement but when my Helicopter goes forward I want it to rotate about 15º but no more and when no forward arrow pressed it has to return to 0º. I’m planning to use an AddTorque but how can I cap de rotation to those angles? For a reference it’s the same move like in Choplifter HD.
Code with the base movement:
using UnityEngine;
using System.Collections;
public class ShipMove : MonoBehaviour {
public float speedx;
public float speedy;
public float speedr;
private Rigidbody box;
public float velx;
public float vely;
public float velz;
// Use this for initialization
void Start () {
box = GetComponent ();
speedx = 90f;
speedy = 20f;
speedr = 10f;
}
// Update is called once per frame
void FixedUpdate () {
float movx = Input.GetAxis (“Horizontal”);
box.AddForce(Vector3.right * movx * speedx, ForceMode.Acceleration);
float movy = Input.GetAxis (“Vertical”);
box.AddForce(Vector3.up * movy * speedy, ForceMode.Acceleration);
box.AddTorque(Vector3.back * movx * speedr, ForceMode.Acceleration);
velx = box.velocity.x;
vely = box.velocity.y;
velz = box.velocity.z;
}
}