HeavenStudioPlus/Assets/Scripts/Transform/LookAlongVelocity.cs
2021-12-18 23:10:43 -05:00

23 lines
No EOL
441 B
C#

using UnityEngine;
public class LookAlongVelocity : MonoBehaviour
{
public float minVelocity = 0.01f;
public new Rigidbody2D rigidbody;
private void Update ()
{
if (rigidbody == null)
return;
if (rigidbody.velocity.magnitude < minVelocity)
return;
var rotation = transform.eulerAngles;
var angle = Vector2.SignedAngle (Vector2.up, rigidbody.velocity);
rotation.z = angle;
transform.eulerAngles = rotation;
}
}