mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-25 11:05:16 +00:00
23 lines
No EOL
441 B
C#
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;
|
|
}
|
|
} |