- Home /
Helicoper Movement Help
Hi all,
I'm working on a helicopter game, but I'm not able to get the helicopter moving properly. I was able to make it move forward, backward, side to side and tilt in the direction of movement, but so far, I was not able to make it rotate without lossing the tilt movement. The helicopter includes a rigidbody attached but at this point I really don't care on using physics as i'm trying to emulate an old game so the movement can be character control insted of physics, but then, i was not able to make it work by that way either
Here is what I achived so far: https://dl.dropboxusercontent.com/u/86664182/helicopterMovement.gif
Here is an example on how I want the helicopter to behave: https://www.youtube.com/watch?v=teMUuNksdek
And here is the code that is attached to the helicopter:
using UnityEngine;
using System.Collections;
public class HelicopterController : MonoBehaviour {
public GameObject helix;
public GameObject secondaryHelix;
public float rotationSpeed;
public float speed;
public float tilt; // The amount of rotation in one side or the other when moving
public float turnSpeed = 30f;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody> ().velocity = movement * speed;
GetComponent<Rigidbody> ().rotation = Quaternion.Euler (GetComponent<Rigidbody> ().velocity.z * tilt, 0.0f, GetComponent<Rigidbody> ().velocity.x * -tilt);
//Try to rotate the helicpter while moving forward and backward - did't work
// if(Input.GetKey(KeyCode.Q))
// transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
//
// if(Input.GetKey(KeyCode.E))
// transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
}
void Update()
{
helix.transform.Rotate (new Vector3 (0.0f, rotationSpeed, 0.0f));
secondaryHelix.transform.Rotate (new Vector3 (rotationSpeed, 0.0f, 0.0f));
}
}
Thanks in advance.
Answer by FortisVenaliter · May 22, 2015 at 03:52 PM
You probably want it to rotate around the transform.up (local) axis rather than the Vector3.up (world) axis.