44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class RecoilManager : MonoBehaviour
|
|
{
|
|
|
|
[Header("Recoil Settings:")]
|
|
public float rotationSpeed = 6.0f;
|
|
public float returnSpeed = 25.0f;
|
|
[Space()]
|
|
|
|
[Header("Hipfire:")]
|
|
public Vector3 recoilRotation = new Vector3(2f, 2f, 2f);
|
|
[Space()]
|
|
|
|
[Header("Aiming:")]
|
|
public Vector3 recoilRotationAiming = new Vector3(0.5f, 0.5f, 0.5f);
|
|
[Space()]
|
|
|
|
private Vector3 currentRotation;
|
|
private Vector3 rot;
|
|
|
|
|
|
public void FixedUpdate()
|
|
{
|
|
currentRotation = Vector3.Lerp(currentRotation, Vector3.zero, returnSpeed * Time.deltaTime);
|
|
rot = Vector3.Slerp(rot, currentRotation, rotationSpeed * Time.fixedDeltaTime);
|
|
transform.localRotation = Quaternion.Euler(rot);
|
|
}
|
|
|
|
public void Fire(bool aiming)
|
|
{
|
|
if (aiming)
|
|
{
|
|
currentRotation += new Vector3(-recoilRotationAiming.x, Random.Range(-recoilRotationAiming.y, recoilRotationAiming.y), Random.Range(-recoilRotationAiming.z, recoilRotationAiming.z));
|
|
}
|
|
else
|
|
{
|
|
currentRotation += new Vector3(-recoilRotation.x, Random.Range(-recoilRotation.y, recoilRotation.y), Random.Range(-recoilRotation.z, recoilRotation.z));
|
|
}
|
|
}
|
|
}
|