- Home /
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;
}
}
That code will only make your plane move along its local forward axis.
Change your transform.forward to transform.position.y, see if that works
@Fla$$anonymous$$gHairball is right: this code only moves forward - and if your plane has a rigidbody and use gravity, it will descend.
Answer by aldonaletto · Aug 16, 2011 at 11:35 PM
If you just want it to ascend vertically, use:
transform.Translate(Vector3.up * liftSpeed * Time.deltaTime);It will go up like a Sea Harrier.
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 ??
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 ins$$anonymous$$d 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.
Your answer
Follow this Question
Related Questions
Developing a 2D flying game similar to Retry by Rovio. 0 Answers
Helicopter controls inverted 1 Answer
control script for airplane 4 Answers
Applied force is increasing over time? 1 Answer
Accelerometer Plane Controls help 0 Answers