x


Airplane Controls - Lift

Hi, I'm trying to make my plane lift off and ascend, but instead it descends. Can anyone help me? Thank you.

var liftSpeed = 20.0;

function FixedUpdate(){

if(Input.GetButton("Lift")) 

{

    transform.position += transform.forward * liftSpeed * Time.deltaTime;

}

}

more ▼

asked Aug 16 '11 at 10:14 PM

jonmar2348 gravatar image

jonmar2348
1 2 3 4

That code will only make your plane move along its local forward axis.

Aug 16 '11 at 10:19 PM flaminghairball

Change your transform.forward to transform.position.y, see if that works

Aug 16 '11 at 11:17 PM logty

@FlamingHairball is right: this code only moves forward - and if your plane has a rigidbody and use gravity, it will descend.

Aug 16 '11 at 11:38 PM aldonaletto
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If you just want it to ascend vertically, use:

  transform.Translate(Vector3.up * liftSpeed * Time.deltaTime);

It will go up like a Sea Harrier.

more ▼

answered Aug 16 '11 at 11:35 PM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

I've started to play around with aircraft dynamics.. I am new to all this .. I have my craft hovering and controls are more like a helicopter.

here's a sample of code

function FlyForward (){
if (Input.GetButton("Forward")){ energy = Time.deltaTime * 50; rigidbody.AddRelativeForce (10,0,0);
rigidbody.AddRelativeTorque (0,0,-4); // tilt forwards print (" Forward Thrust Active "); }

I am trying to achieve stable turns. Currently my craft tends to yaw rather than bank. Is it ok to use rigidbody.AddRelativeForce as apposed to rigidbody.AddForce ??

Jun 10 '12 at 04:04 PM Mickman

AddForce is based on world coordinates. For a spaceship or airplane, it makes more sense to use AddRelativeForce, because the ship will move in its local direction - a jet will push the airplane to its forward direction, for instance. For an airplane, the gravity is the only world related force; for a spaceship, usually there are no world based forces.
But if you apply a relative force and a relative torque, the airplane may behave like an untied party balloon when we release its neck - the force will push it forward, but the torque will make the forward direction change.
A better alternative is to make the airplane model a child of the actual rigidbody: create an empty game object, add a suitable collider (box or capsule) and a rigidbody - this will be your actual airplane. Child the airplane model to it, and when necessary fake the banking by modifying the model's transform.localEulerAngles. Applying torque to a rigidbody usually isn't a good idea: the rigidbody spins instead of just turn to the desired direction. To turn left or right, for instance, it's better to rotate the transform with transform.Rotate - the rigidbody follows the transform, thus it will go in the new direction.

Jun 10 '12 at 09:29 PM aldonaletto
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x141
x68
x46
x15

asked: Aug 16 '11 at 10:14 PM

Seen: 1011 times

Last Updated: Jun 10 '12 at 09:29 PM