mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 17:57:39 +02:00
Fork Lifter Spaghetti Code
This commit is contained in:
23
Assets/Scripts/Transform/LookAlongVelocity.cs
Normal file
23
Assets/Scripts/Transform/LookAlongVelocity.cs
Normal file
@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user