// Update is called once per frame
        void LateUpdate()
        {
            if (Time.unscaledDeltaTime == 0)
            {
                return;
            }
            var curPosition   = cachedTransform.position;
            var positionDelta = (curPosition - previousPosition) / Time.unscaledDeltaTime;

            var curRotation   = cachedTransform.rotation;
            var rotationDelta = (curRotation.eulerAngles - previousRotation) / Time.unscaledDeltaTime;

            if (!positionDelta.IsNaN())
            {
                Velocity.AddDataPoint(positionDelta);
                previousPosition = curPosition;
            }

            if (!rotationDelta.IsNaN())
            {
                AngularVelocity.AddDataPoint(rotationDelta);
                previousRotation = curRotation.eulerAngles;
            }

            if (Events)
            {
                var eventVelocity = EventsSendLocalVelocity ? transform.TransformVector(Velocity) : Velocity;
                XVelocityEvent?.Invoke(eventVelocity.x);
                YVelocityEvent?.Invoke(eventVelocity.y);
                ZVelocityEvent?.Invoke(eventVelocity.z);
                VelocityEvent?.Invoke(eventVelocity);
                VelocityMagnitudeEvent?.Invoke(eventVelocity.magnitude);
            }
        }
Exemple #2
0
 private void Start()
 {
     OnHealthChanged.Invoke(_health, _maxHealth);
 }