Hi, I am working on a helicopter control script that you can quickly attach to any object you want to be a helicopter, but I’ve come into one problem: the lines that say AddRelativeForce do add the force but it’s not adding it in the right directions. For example, i want my heli to angle downwards (rotating on the z axis) so it can look at the ground, and it works if i’m at like a global 45 degree angle but if i’m at like a global 180 degrees, it will try to angle on the z, get stuck on…something, and then rotate on the x axis.
var throttle : float;
var rightT : float;
var leftT : float;
var forwardT : float;
var backT : float;
var RightTurnSpeed : float;
var LeftTurnSpeed : float;
var heightLimit : float;
function Update () {
leftT = rightT * -1;
Nthrottle = throttle * -1;
backT = forwardT * -1;
LeftTurnSpeed = RightTurnSpeed * -1;
transform.rotation.x = 0;
if (Input.GetKey("left shift") gameObject.transform.position.y < heightLimit) {
rigidbody.AddForce (transform.up * throttle);
}
else
{
rigidbody.AddForce (transform.up * 15500);
}
if (Input.GetKey("d")) {
rigidbody.AddForce (transform.forward * rightT);
rigidbody.AddRelativeTorque (2000, 0, 0);
}
if (Input.GetKey("a")) {
rigidbody.AddForce (transform.forward * leftT);
rigidbody.AddRelativeTorque (-2000, 0, 0);
}
if (Input.GetKey("left ctrl")) {
rigidbody.AddForce (transform.up * Nthrottle);
}
if (Input.GetKey("w")) {
rigidbody.AddForce (transform.right * backT);
}
if (Input.GetKey("s")) {
rigidbody.AddForce (transform.right * forwardT);
}
if (Input.GetKey("right")) {
rigidbody.AddRelativeTorque (0, RightTurnSpeed, 0);
}
if (Input.GetKey("left")) {
rigidbody.AddRelativeTorque (0, LeftTurnSpeed, 0);
}
if (Input.GetKey("up")) {
rigidbody.AddRelativeTorque (0, 0, 40000);
}
if (Input.GetKey("down")) {
rigidbody.AddRelativeTorque (0, 0, -40000);
}
if (gameObject.transform.rotation.z > 4) {
rigidbody.AddRelativeTorque (0, 0, -160000);
}
if (gameObject.transform.rotation.z < -4) {
rigidbody.AddRelativeTorque (0, 0, 160000);
}
if (gameObject.transform.rotation.x < -6) {
rigidbody.AddRelativeTorque (4000, 0, 0);
}
if (gameObject.transform.rotation.x > 6) {
rigidbody.AddRelativeTorque (-4000, 0, 0 );
}
}
I have tried removing the angle correction parts, but that does not do anything.