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

50 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Player.Equip;
using BITKit;
using BITKit.Entities;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BITFALL.Player.Movement
{
public class EquipSway : EntityComponent
{
[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;
public override void OnAwake()
{
_movement = entity.Get<IEntityMovement>();
_equipService = entity.Get<IEquipService>();
}
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;
}
currentPosition = Vector3.Lerp(currentPosition,velocity * posValue,posDelta * deltaTime);
currentRotation = Quaternion.Lerp(currentRotation,Quaternion.Euler(angularVelocity * rotValue),rotDelta * deltaTime);
locationAdditive.AddEuler(currentRotation.eulerAngles);
locationAdditive.AddPosition(currentPosition);
}
}
}