- Home /
Helicopter Controls
Hi! I am trying to make a Helicopter, but the results so far were pretty... disappointing...
I wish to make a Helicopter. But not just a wish, it's a DREAM. I am actually starting to go insane because of this xD
I wanted to make a FULL WORKING HELICOPTER, so i started it. I made glass for the windows, i adjusted both the rotors (main and rear), i adjusted the camera, the setup, but now i am stuck on what i believe to be the hardest part of it. I wanted to make the Controls, but i am having some serious problems. I have a script that make the helicopter fly when i press the space bar, but i am having trouble with the directional controls.
I want to make the helicopter smoothly start to rotate when the player press A or D. Rotate 90 degrees. I also want to make the helicopter go forward when the player press W and backward when the player press S.
I've tried everything, but i can't do this =( I am just a beginner at scripting yet, so i don't know much about this. I tried some tutorials, asked some questions, but i still don't know what to do! How can i make this? I seriously don't know. Could someone help me? This is making me crazy =\
So far, i could only make some strange combination of things that resulted in my helicopter crashing in the ground, going insane while in the air or literally starting to move like it was rebelling itself, but it's because my scripts are ridiculously bad made...
This is my helicopter. I don't know if anyone can help me, but i still would like to thank you guys, because i didn't knew even the basic things when i started and you all helped me, and i am slowly becoming a good developer =)
Feel free to send me private message on unity-forum. It's quite broad and complex idea, depending mostly on how perfect beahaviour You want, and doesn't fit well into QA format. Still better than many other questions I've seen.
Answer by ForeignGod · Sep 21, 2016 at 09:20 AM
This is not tested but should give you some ideas.
//Adjust these!
var speed = 30;
var fspeed = 30;
var bspeed = 30;
var lift = 30;
//
var helirb: Rigidbody;
function Start() {
helirb = GetComponent.<Rigidbody>();
}
function Update () {
if (Input.GetKey(KeyCode.A)){
transform.Rotate(Vector3.left * speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D)){
transform.Rotate(-Vector3.right * speed * Time.deltaTime);
}
}
function FixedUpdate () {
if (Input.GetKey(KeyCode.W)){
helirb.Addforce(transform.forward * fspeed * Time.deltaTime);
//Add tilt rotation maybe for visual purposes?
}
if (Input.GetKey(KeyCode.S)){
helirb.AddForce(-transform.forward * fspeed * Time.deltaTime);
//Add tilt rotation maybe for visual purposes?
}
if (Input.GetKey(KeyCode.Space)){
helirb.AddForce(transform.up * lift * Time.deltaTime);
}
}
EDIT: Fixed some small errors.
There are some errors on it:
I could only repair some things, but there are some errors that i believe can't be fixed without changing the entire script.
Try out the newest revision. Just remember to edit your ridigbody's settings accordingly. $$anonymous$$ight seem like it doesn't work at first :)
I am still getting "back is not a member of unity engine transform" =\