Mouse movement to move camera

Hi!

I’m looking for some base, library or script than have the camera behaviour as in these examples:

I can’t find the way to replicate that behavior. The camera movement is very smooth and never has a jump, very clean, soft.
Any suggestions?

Help please!

The controls remind me at the following official three.js example: three.js webgl - materials - normal map [Lee Perry-Smith]

I guess you can use the demo as a foundation for your own code.

1 Like

this is quite easy to do: Baked AO - CodeSandbox

the code:

obj.rotation.y = THREE.MathUtils.lerp(obj.rotation.y, (mouse.x * Math.PI) / 10, 0.1)
obj.rotation.x = THREE.MathUtils.lerp(obj.rotation.x, (mouse.y * Math.PI) / 10, 0.1)
1 Like

Both solutions are great, this second one is more simple and easy to control. Just one thing.

You can use ( mouse.x - (window.innerWidth / 2) ) instead of mouse.x to use de center of the screen to control the rotation.

Thanks!

right, forgot to mention that. the mouse object in that code is already centred, good point!