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

57 lines
1.6 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;
using UnityEngine;
using UnityEngine.InputSystem;
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-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
if (_equipService.AllowScope is false)
angularVelocity = default;
2023-10-02 23:24:56 +08:00
}
2023-11-21 18:05:18 +08:00
2023-09-01 14:33:54 +08:00
currentPosition = Vector3.Lerp(currentPosition,velocity * posValue,posDelta * deltaTime);
2023-11-15 23:54:54 +08:00
currentRotation = Quaternion.Slerp(currentRotation,Quaternion.Euler(angularVelocity * rotValue),rotDelta * deltaTime);
2023-11-21 18:05:18 +08:00
currentPosition+= new Vector3(
angularVelocity.y,
angularVelocity.x,
angularVelocity.z
) * (posValue * deltaTime * 4);
2023-11-15 23:54:54 +08:00
2023-09-01 14:33:54 +08:00
locationAdditive.AddEuler(currentRotation.eulerAngles);
locationAdditive.AddPosition(currentPosition);
}
}
}