Hi all!
The answer might be painfully simple, but it’s evading me ))
Here’s the situation: I have a simple ship with rigidbody that accelerates, strafes and jumps on the plane. On their own all controls are working perfectly (say, the ball is travelling forward, I press jump it goes up it comes down, gravity is fine, etc.)
However, if after I press jump and the ship is still in the air I start using other controls (strafe, accelerate/brake) it floats in the air much longer, almost like gravity doesn’t apply anymore. Only when I release other keys, it resumes functioning normally.
void FixedUpdate () {
ShipMovement ();
}
void ShipMovement () {
//Jump
if (onGround) {
if (Input.GetKeyDown (KeyCode.Space)) {
rb.velocity = new Vector3 (rb.velocity.x, Gravity * 7f, 0f);
onGround = false;
}
}
//Left
if (Input.GetKey (KeyCode.A)) {
rb.velocity = new Vector3 (rb.velocity.x, 0f, Steering * -1);
}
if (Input.GetKeyUp (KeyCode.A)) {
rb.velocity = new Vector3 (rb.velocity.x, 0f, 0f);
}
//Right
if (Input.GetKey (KeyCode.D)) {
rb.velocity = new Vector3 (rb.velocity.x, 0f, Steering);
}
if (Input.GetKeyUp (KeyCode.D)) {
rb.velocity = new Vector3 (rb.velocity.x, 0f, 0f);
}
//Accelerate
if (Input.GetKey (KeyCode.W)) {
if (speed < 100) {
speed ++;
rb.velocity = new Vector3 (transform.localScale.x * speed * Acceleration * -1f, 0f, 0f);
}
}
//Deccelerate
if (Input.GetKey (KeyCode.S)) {
if (speed > 0) {
speed--;
rb.velocity = new Vector3 (transform.localScale.x * speed * Acceleration * -1f, 0f, 0f);
}
}
}