Exemple #1
0
    void FixedUpdate()
    {
        Vector2 direction = movement.normalized;

        if (direction.magnitude > 0)
        {
            float angle = Vector2.SignedAngle(Vector2.up, direction);
            float diff  = Mathf.DeltaAngle(transform.eulerAngles.z, angle);
            diff = MathExtensions.ClampMagnitude(diff, 0.0f, maxRotationDiffMagnitude);

            rigidbody2D.AddForce(transform.up * movementForce * Time.fixedDeltaTime);
            rigidbody2D.AddTorque(diff * rotationTorqueMultiplier * Time.fixedDeltaTime);
        }
    }