# How to create shake or wobble effect on mouse cursor?

I have imported new Input System so I can manipulate cursors position, but I would have no idea how to actually set position with new values which would get me that effect. Example:

``````if(Input.GetKey(KeyCode.Space))
{
mousePositionNew = Input.mousePosition;
float wobbleX = 1 * Mathf.Sin(Time.time * 5);
float wobbleY = 1 * Mathf.Cos(Time.time * 5);
mousePositionNew += new Vector2(wobbleX, wobbleY);
Mouse.current.WarpCursorPosition(new Vector2(mousePositionNew.x, mousePositionNew.y));
}
``````

All that this does is moves cursor up in half circular motion.

Is the problem that your modifications don’t get applied to the cursor as expected? Or are you looking for guidance on how to calculate an x,y offset that feels wobbly?

If you are looking for pseudo-random movement, you could look into Perlin Noise.

I’ve used that to add some wobble to some characters:

``````//noiseMagnitude is how big the movement will be
//timeScale is how quick the movement will be
//xRand and yRand are just some random numbers so that each instance of my object
//  would move in a different random way. It also makes the x and y offsets move differently from each other.
float xOffset = -(noiseMagnitude/2f) + noiseMagnitude * Mathf.PerlinNoise(Time.time * timeScale, xRand);
float yOffset = -(noiseMagnitude/2f) + noiseMagnitude * Mathf.PerlinNoise(Time.time * timeScale, yRand);
``````