2016-04-17 15 views
-2

Hallo Leute, ich habe ein paar Probleme mit der Rotation meines Raumschiffs. Wenn ich den Pfeil nach links drücke und auf den Pfeil nach rechts wechsle, wird die Drehung sofort umgeschaltet. Wie kann ich es glätten?unity3d spaceshooter Bewegung

Video: https://sendvid.com/fek9izy3

void FixedUpdate() 
{ 
    Rigidbody rb = GetComponent<Rigidbody>(); 
    float moveHorizontal = Input.GetAxis("Horizontal"); 
    float moveVertical = Input.GetAxis("Vertical"); 

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); 
    rb.velocity = movement * speed; 

    rb.position = new Vector3 
    (
     Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 
     0.0f, 
     Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) 
    ); 

    rb.rotation = Quaternion.Euler(0.0f, 180, rb.velocity.x * -tilt); 
} 

}

Antwort

0

Wenn Sie realistische Physik wollen, nicht direkt eine Starrkörperposition oder Rotation ändern. Verwenden Sie stattdessen Rigidbody.AddForce für lineare Bewegung und Rigidbody.AddTorque für Rotation.

glatt, um das Schiff zu drehen, würden Sie so etwas tun:

float speed = 10f; 

rb.AddTorque(new Vector3(0f, 0f, moveHorizontal * speed));