- Home /
Question by
LittleJohnGames · Apr 26, 2015 at 07:18 PM ·
physicsrigidbodyrigidbody.addforce
Flight Control Issues
I have created a simple flight controller script, which works fine to begin with, but its one problem is, it will cease to work after a few turns. I need the plane game object to move forward, but it will just go off in random directions after the rotation is altered. I can't seem to figure out the problem.
var MoveSpeed : int;
var Speed : float;
var RotSpeed : float;
var lift : float;
function Update () {
Speed = Speed;
Speed = Input.GetAxisRaw("Slider");
if(Speed == 1){
Speed = Speed * MoveSpeed;
}
else if(Speed == -1){
Speed = Speed * 0;
}
var ZRotSpeed : float = Input.GetAxis("Vertical") * RotSpeed;
var XRotSpeed : float = Input.GetAxis("Horizontal") * RotSpeed;
if(Speed > 0){
GetComponent.<Rigidbody>().useGravity = false;
}
if(Speed == 0){
GetComponent.<Rigidbody>().useGravity = true;
}
GetComponent.<Rigidbody>().AddForce(-Speed, 0, 0);
GetComponent.<Rigidbody>().AddTorque(0, 0, ZRotSpeed);
GetComponent.<Rigidbody>().AddTorque(XRotSpeed, 0, 0);
GetComponent.<Rigidbody>().AddForce(0, lift, 0);
}
Thanks in advance
Comment
Your answer
Follow this Question
Related Questions
add force to object that has 2 different rigid bodies 0 Answers
Rigidbody.velocity seems to be breaking jumping physics 0 Answers
Sudden surge of force applied to a rigidbody from continous jumping. 1 Answer
Link two rigidbodies 1 Answer
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers