laggy camera movement

hello guys.
I’m working on some tiny 3d game with fps camera and lately I stuck with this annoying bug That I can’t find fix to.
the problem is that when I move my camera around and move to any direction I got some render stutters/lags while the fps is stable fixed at 60fps.
I found out that this happens only when I move the mouse and not from raw keyboard movement.

I think it’s have something to do with my math but I’m not sure about it.
can someone take a look at my mouse class?

package com.raise3d.engine.scene.behaviors;

import org.joml.Vector3f;
import com.raise3d.engine.assets.AssetsManager;
import com.raise3d.engine.input.Input;
import com.raise3d.engine.input.Keyboard;
import com.raise3d.engine.main.MainLoop;
import com.raise3d.engine.scene.Actor;
import com.raise3d.engine.scene.Behavior;

public class Camera implements Behavior
{
	private float camera_speed;
	private float sensitivity;
	public static float yaw, pitch;
	
	public void OnInit(Actor self, AssetsManager assets, Input input) // init method
	{
		camera_speed=0.005f;
		sensitivity=0.15f;
		yaw=0;
		pitch=0;
		self.setDirection(new Vector3f(0,0,0));
		self.setLocation(new Vector3f(0,1.75f,0));
	}
	
	public void OnStep(Actor self, Input input, float delta) // update method
	{
		float speed=camera_speed*delta;
		float xoffset=(input.getMouse().getMouseOffsetX()*sensitivity);
		float yoffset=(input.getMouse().getMouseOffsetY()*sensitivity);
		if (xoffset>10)
		{
			xoffset=10;
		}
		
		if (xoffset<-10)
		{
			xoffset=-10;
		}
		
		if (yoffset>10)
		{
			yoffset=10;
		}
		
		if (yoffset<-10)
		{
			yoffset=-10;
		}

		if (xoffset!=0 || yoffset!=0)
		{
			yaw+=xoffset;
			pitch+=yoffset;  		
			if(pitch > 89.0f)
			{
				pitch =  89.0f;
			}
			if(pitch < -89.0f)
			{
				pitch = -89.0f;
			}
			Vector3f d = new Vector3f();
			d.x = (float) (Math.cos(Math.toRadians(pitch)) * Math.cos(Math.toRadians(yaw)));
			d.y = (float) Math.sin(Math.toRadians(pitch));
			d.z = (float) (Math.cos(Math.toRadians(pitch)) * Math.sin(Math.toRadians(yaw)));
			d.normalize();	
			self.setDirection(d);
		}
		
		Vector3f motion = new Vector3f();
		Vector3f moved = new Vector3f();
		moved.x = (float) (Math.cos(Math.toRadians(0)) * Math.cos(Math.toRadians(yaw)));
		moved.y = (float) Math.sin(Math.toRadians(0));
		moved.z = (float) (Math.cos(Math.toRadians(0)) * Math.sin(Math.toRadians(yaw)));
		moved.normalize();	
		
		if (input.getKeyboard().isKeyDown(Keyboard.KEY_W))
		{
			motion.add(moved);
		}
		
		if (input.getKeyboard().isKeyDown(Keyboard.KEY_S))
		{
			motion.sub(moved);
		}
		
		if (input.getKeyboard().isKeyDown(Keyboard.KEY_D))
		{
			motion.add(moved.cross(new Vector3f(0,1.0f,0)).normalize());
		}
		
		if (input.getKeyboard().isKeyDown(Keyboard.KEY_A))
		{
			motion.sub(moved.cross(new Vector3f(0,1.0f,0)).normalize());
		}
		
		if (input.getKeyboard().isKeyDown(Keyboard.KEY_LEFT_SHIFT))
		{
			speed*=2;
		}
		
		if (input.getKeyboard().isKeyDown(Keyboard.KEY_LEFT_CONTROL))
		{
			speed/=2;
		}

		self.setLocation(self.getLocation().add(motion.mul(speed)));
		MainLoop.getAudioManger().setListenerPosition(self.getLocation());
		MainLoop.getAudioManger().setListenerDirection(self.getDirection());
		MainLoop.getRender().setCameraLocation(self.getLocation());
		MainLoop.getRender().setCameraDirection(self.getDirection());
		MainLoop.getRender().UpdateFrustum();
		
	}

	public String getName() 
	{
		return "camera";
	}

	public void OnCollide(Actor self, Actor other) 
	{
		
	}
}

If the keyboard input does, as you say it does, experience no lag, then the problem seems it must be with your input system’s updating. I don’t know what could be wrong with that, that’s just where I would look next.

Are you using lwjgl3 or lwjgl2?

If you are using lwjgl2, there was a bugged version which reading the polled mouse position would lag. I told Spasi about this a few months (a year?) ago and he fixed it.