BITFALL/Assets/Artists/Scripts/Equip/EquipSway.cs

76 lines
2.0 KiB
C#
Raw Normal View History

2023-09-01 14:33:54 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2023-10-02 23:24:56 +08:00
using BITFALL.Player.Equip;
2023-09-01 14:33:54 +08:00
using BITKit;
using BITKit.Entities;
2023-12-15 00:08:02 +08:00
using Unity.Mathematics;
2023-09-01 14:33:54 +08:00
using UnityEngine;
using UnityEngine.InputSystem;
2023-12-15 00:08:02 +08:00
using Random = UnityEngine.Random;
2023-09-01 14:33:54 +08:00
namespace BITFALL.Player.Movement
{
2023-10-30 01:25:53 +08:00
public class EquipSway : EntityBehavior
2023-09-01 14:33:54 +08:00
{
[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;
2023-10-02 23:24:56 +08:00
private IEquipService _equipService;
2023-12-15 00:08:02 +08:00
[Inject] private IHealth _health;
2023-09-01 14:33:54 +08:00
public override void OnAwake()
{
2023-10-30 01:25:53 +08:00
_movement = UnityEntity.Get<IEntityMovement>();
_equipService = UnityEntity.Get<IEquipService>();
2023-09-01 14:33:54 +08:00
}
public override void OnLateUpdate(float deltaTime)
{
2023-10-20 19:31:12 +08:00
deltaTime = Mathf.Clamp(deltaTime, 0, 0.32f);
2023-09-01 14:33:54 +08:00
var velocity = _movement.LocomotionBasedVelocity;
var angularVelocity = _movement.AngularVelocity;
2023-10-02 23:24:56 +08:00
if (_equipService.Zoom.Allow)
{
velocity = default;
2023-11-02 20:58:55 +08:00
angularVelocity = default;
2023-10-02 23:24:56 +08:00
}
2023-11-30 00:23:23 +08:00
//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(
2023-11-21 18:05:18 +08:00
angularVelocity.y,
angularVelocity.x,
angularVelocity.z
2023-12-15 23:44:39 +08:00
) * (posValue * deltaTime * 8);
2023-11-15 23:54:54 +08:00
2023-12-15 00:08:02 +08:00
if (_health.HealthPoint <= 50)
{
var t = math.sin(Time.time*5) * 0.001f;
currentPosition += (Vector3)Random.insideUnitCircle * t ;
}
2023-09-01 14:33:54 +08:00
locationAdditive.AddEuler(currentRotation.eulerAngles);
locationAdditive.AddPosition(currentPosition);
}
}
}