- Home /
Creating my own flight physics?
Hi. I'm trying to make some realistic flight physics.
First.. I'm trying to make the plane fly.
This is my aircraft:
What would be my best approach on making flight physics?
This is my current script:
int curr_Speed;
float lift;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
curr_Speed = (int)(rigidbody.velocity.magnitude * 1 / 0.3f);
}
void FixedUpdate() {
rigidbody.AddRelativeForce(transform.forward * 4.5f);
}
This only make the plane move forward (of course). What would be my next step and where should I apply rotation forces?
Thanks in advance.
Andreas.
Flight physics can be fairly complicated. If you are asking for design help, then Unity Forums is a better place to post. Unity Answers focuses on single, specific questions. There are packages in the Asset store (including one free one) just on flight physics. You can use AddRelativeTorque() to turn the plane.
Answer by bhavinbhai2707 · Mar 26, 2017 at 08:38 PM
Probably u should try this script. . . .this is not really an advance script but just an example of where u can start
//C# SCRIPT
public float maxSpeed; // Our maximum speed allowed.
public float decAltSpeed; //Decrease Altitude.
public float incAltSpeed; // Increase Altitude.
public float curSpeed; // Current Speed;
public float applySpeed; // How much force to apply (Forward).
public float airBrakeForce; // Breaks.
private Rigidbody myRigid; // Our Rigidbody.
void Start(){
myRigid = GetComponent<Rigidbody>(); // Gets the players Rigidbody.
}
void FixedUpdate(){
curSpeed = myRigid.velocity.z;
if(curSpeed >= maxSpeed){
//If our speed maxes out to our maxSpeed we restrict our plane from going any faster.
applySpeed = curSpeed;
}
if(Input.GetKey(KeyCode.W)){
//Apply Accelleration
myRigid.AddRelativeForce(Vector3.forward * applySpeed);
if(curSpeed >=incAltSpeed){
myRigid.AddRelativeForce(Vector3.up * AnyNumberYouWant);
}
}
if(Input.GetKey(KeyCode.S)){
//Apply BREAKS
myRigid.AddRelativeForce(Vector3.back * airBrakeForce);
if(curSpeed <= decAltSpeed){
myRigid.AddRelativeForce(Vector3.down * AnyNumberYouWant);
}
}
}
void Update(){
//NOT REALISTIC ROTATIONS
//You may have to move the '-' sign to the other one (- means opposite) E.G. - Negative so I THINK -Vector.up is left. Could be wrong though.
if(Input.GetKey(KeyCode.A)){
transform.rotate(-Vector3.up * 15 * Time.deltaTime);
}
if(Input.GetKey(KeyCode.D)){
transform.rotate(Vector3.up * 15 * Time.deltaTime);
}
}
}
hope u can get a idea
Answer by theGugu · Mar 28, 2017 at 04:41 AM
If you want to do it well, you'll probably have to consider lift and downforce to the wings (depending on velocity and pressure) and variable gravity (depending on distance): g=G*Mearth/(radius+heightfromwater)^2 You should try implement windzones and high/low pressure zones
If you calculate all of this into separated vectors, you can finally sum all together and get the resulting force applied to the aircraft
Your answer
Follow this Question
Related Questions
Realistic 2D flight physics? 0 Answers
Dynamic flight physics help. 0 Answers
How can I accelerate my Object to a maximum speed 1 Answer