I have a gun sway and recoil script, but whenever I’m in an animation state (even an empty one) It overrides the lerp, and the sway and recoil just don’t work. This is pretty frustrating considering the only other person I found with this problem had it back in 2013, and no one answered, my code for the sway just to give you an idea:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sway : MonoBehaviour {
public float swayAmount;
public float smoothingAmount;
private Vector3 initialPosition;
// Use this for initialization
void Start () {
initialPosition = transform.localPosition;
}
// Update is called once per frame
void Update () {
float mouseX = Input.GetAxis("Mouse X") * swayAmount;
float mouseY = Input.GetAxis("Mouse Y") * swayAmount;
Vector3 finalPosition = new Vector3(-mouseX, -mouseY, 0);
transform.localPosition = Vector3.Lerp(transform.localPosition, finalPosition + initialPosition, Time.deltaTime * smoothingAmount);
}
}