Smoothen Mouse Axis Input

Hey Guys! I’m currently working on a FPS experimental hobby thingy, and i’ve run into problem recently:

To make the whole thing look more realistc i tried to implement the movement a weapon does in every normal FPS, where the weapon rotates up to a certain amount of degrees based on the speed of your input, f.e. the speed you’re giving your mouse. At the moment i’ve got this code:

private var start_rotation_y;

function Start() {
	start_rotation_y = transform.localEulerAngles.y;

function FixedUpdate() {
	var mouseSpeedX:float = Input.GetAxisRaw("Mouse X");
	var speedRounded:float = Mathf.Round(mouseSpeedX * 3);
	transform.localEulerAngles.y = start_rotation_y + speedRounded;

The problem with that is, that the weapon moves but the movement is very jittery, when I would rather have it being smooth and due to this realistic looking.

I’ve tried a few things, but they all ended up being jittery, so i hope someone in the community knows a proper fix for that!

Greets, remoteplayfreak!

I think that so long as you’re mapping mouse input directly to your camera rotation, you’re going to get some erratic behavior. have you considered doing a Quaternion.Slerp to smooth the values over time? Even if the time is as low as a tenth of a second it should reduce jittering considerably (because that’s honestly how mouse smoothing works, it just averages your input over X amount of time).

I’ve actually tried to avoid Quaternions, because i prefer localEulerAngels, because we recently did that in school :wink:

Nevertheless: Could you possibly tell me a little bit about Quaternions because i have no clue how to use them!