quantum-space-buddies/QSB/Player/RemotePlayerVelocity.cs

19 lines
502 B
C#
Raw Normal View History

2022-07-11 12:53:29 +00:00
using UnityEngine;
namespace QSB.Player;
public class RemotePlayerVelocity : MonoBehaviour
{
2022-07-11 12:53:29 +00:00
private Vector3 _prevRelPosition;
public Vector3 Velocity { get; private set; }
public void FixedUpdate()
{
2022-07-11 12:53:29 +00:00
var reference = Locator.GetCenterOfTheUniverse().GetStaticReferenceFrame().transform;
var currentRelPosition = reference.InverseTransformPoint(transform.position);
Velocity = (currentRelPosition - _prevRelPosition) / Time.fixedDeltaTime;
_prevRelPosition = currentRelPosition;
}
}