示例#1
0
    void FixedUpdate()
    {
        if (_paused || _stopped)
        {
            return;
        }

        // Add a vector related to the steering
        GetComponent <Rigidbody2D>().velocity = analogControl.GetNormalizedSteering() * _carSpeed;

        // Turn towards the direction we're traveling
        if (GetComponent <Rigidbody2D>().velocity.magnitude > 0.4f)
        {
            float targetAngle = Mathf.Atan2(GetComponent <Rigidbody2D>().velocity.y, GetComponent <Rigidbody2D>().velocity.x) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, targetAngle), 8 * Time.deltaTime);
        }
    }
 protected override void PostUpdate()
 {
     _input = analogControl.GetNormalizedSteering();
 }