- Home /
Defining specific controls for rotation.
I'm attempting to make a helicopter game. It'll be like the endless runners so I only want the helicopter to go up and down however, I would also like slight rotation along the z axis to give it that 'lift' 'drop' feel.
My current script gives my heli the rotation I am after however it's tied to the horizontal input (left right, a, d). Could someone advise me on the best way to achieve the following:
Helicopter rotates left (backwards slightly) and transforms upwards when space is pressed. And when released goes into 'falling' by translating downwards whilst also rotated slightly forward.
My script is below:
using UnityEngine;
using System.Collections;
public class Helicontrol : MonoBehaviour {
public float tiltAngle = 20.0f;
public float smooth = 2.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//get the horizontal axis only
float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
Quaternion target = Quaternion.Euler(0, 0, -tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}
Thank you for any help you can provide :)
Euden
Your answer
Follow this Question
Related Questions
Get slerp to work just as LookAt(,Vector3.right) does 1 Answer
Rigidbody spins out of control when colliding into corner 0 Answers
Problem changing rotation of 3rd Person Controller 1 Answer
Follow x rotation of a target object. 1 Answer
How to get Angle float of specific axis.(Turret clamping related). 2 Answers