#Weapon Sway Is Glitching Out

1 messages · Page 1 of 1 (latest)

heavy owl
#

and here's the script:

using System;
using UnityEngine;

public class WeaponSway : MonoBehaviour {
    [Header("Sway Settings")]
    [SerializeField] private float smooth;
    [SerializeField] private float swayMultiplier;

    private void Update() {
        // Get mouse input
        float mouseX = Input.GetAxisRaw("Mouse X") * swayMultiplier;
        float mouseY = Input.GetAxisRaw("Mouse Y") * swayMultiplier;

        // Caclculate target rotation
        Quaternion rotationX = Quaternion.AngleAxis(-mouseY, Vector3.right);
        Quaternion rotationY = Quaternion.AngleAxis(-mouseX, Vector3.up);

        Quaternion targetRotation = rotationX * rotationY;

        // Rotate
        transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, smooth * Time.deltaTime);
    }
}
heavy owl
#

The only time it doesn’t glitch out insanely is when I look up

#

But looking left and right seems a little glitchy but still very noticeable