using System; using System.Collections; using System.Collections.Generic; using BITFALL.Player.Equip; using BITKit; using BITKit.Entities; using Unity.Mathematics; using UnityEngine; using UnityEngine.InputSystem; using Random = UnityEngine.Random; namespace BITFALL.Player.Movement { public class EquipSway : EntityBehavior { [SerializeField] private float rotDelta; [SerializeField] private float rotValue; [SerializeField] private float posDelta; [SerializeField] private float posValue; [SerializeField] private LocationAdditive locationAdditive; private Quaternion currentRotation; private Vector3 currentPosition; private IEntityMovement _movement; private IEquipService _equipService; [Inject] private IHealth _health; public override void OnAwake() { _movement = UnityEntity.Get(); _equipService = UnityEntity.Get(); } public override void OnLateUpdate(float deltaTime) { deltaTime = Mathf.Clamp(deltaTime, 0, 0.32f); var velocity = _movement.LocomotionBasedVelocity; var angularVelocity = _movement.AngularVelocity; if (_equipService.Zoom.Allow) { velocity = default; angularVelocity = default; } //Debug.Log(MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles) ); currentPosition = Vector3.Lerp(currentPosition, velocity * posValue, posDelta * deltaTime); currentRotation = Quaternion.Slerp(currentRotation, Quaternion.Euler((angularVelocity - new Vector3() { x = _equipService.Zoom.Allow ? 0 : MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles).x * 0.05f } * rotValue ) ), rotDelta * deltaTime); currentPosition += new Vector3( angularVelocity.y, angularVelocity.x, angularVelocity.z ) * (posValue * deltaTime * 8); if (_health.HealthPoint <= 50) { var t = math.sin(Time.time*5) * 0.001f; currentPosition += (Vector3)Random.insideUnitCircle * t ; } locationAdditive.AddEuler(currentRotation.eulerAngles); locationAdditive.AddPosition(currentPosition); } } }