- Home /
Answered my own question
How to move an airplane in the Z axis?
I'm using a modified plane-flying script from the Asset Store on the player's plane. Now, it's a fine script, BUT it's hard to change the script without breaking something.
Specifically, I'm trying to give the player the ability to slide on the X and Y axis, in addition to your normal thrust on the Z-axis. But the script moves the player along the Z-axis by setting the rigidbody's velocity, and I'm trying to move the player along the X and Y axes by using AddRelativeForce. "velocity =" and AddRelative Force don't play well with each other.
How do I make the plane move properly on all three axes?
Here's the relevant code: relevant variables:
public float speed = 20.0f; //"Base Speed", "Primary flight speed, without afterburners or brakes"
public float speedX = 20.0f; //"Horizontal Slide Speed", "Slide speed along the X-axis"
public float speedY = 20.0f; //"Vertical Slide Speed", "Slide speed along the Y-axis"
public float afterburner_speed = 40f; //Afterburner Speed", "Speed when the button for positive thrust is being held down"
public float slow_speed = 4f; //"Brake Speed", "Speed when the button for negative thrust is being held down"
float currentMag = 0f; //Current speed/magnitude (this is the player ship's thrust magnitude, set earlier in the script)
-----------------------------------------------------------------
thrust coding
//Apply all these values to the rigidbody on the container.
GetComponent<Rigidbody>().AddRelativeTorque(
(pitch * turnspeed * Time.deltaTime),
(yaw * turnspeed * Time.deltaTime),
(roll * turnspeed * (rollSpeedModifier / 2) * Time.deltaTime));
GetComponent<Rigidbody>().velocity = transform.forward * currentMag; //Apply speed
GetComponent<Rigidbody>().AddRelativeForce(
(Input.GetAxis("Horizontal") * speedX * 2),
(Input.GetAxis("Vertical") * speedY),
0
) ;
I just get the feeling that I'm missing something here, that there's some way to fix the problem by using AddRelativeForce on all axes. I KNOW there is; I achieved all-axes flying once before, before stupidly deleting my old work and having to start from scratch.
So, can anyone help a newb make planes fly?
Thanks!
Follow this Question
Related Questions
Object flickers back and forth if it reaches mouseposition. 0 Answers
How to set velocity to new direction after rotation? 0 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Help with sliders 1 Answer
How to Pick up 1 collider Object at a time, Vs. all at once? 2 Answers