How do I stop the camera being able to rotate 360 degrees in the first person movement script?

How would I make it so the camera can’t rotate fully around the Y axis. The camera is able to rotate 360 degrees in one direction. Sorry, It’s hard to explain. Here’s my project: https://playcanvas.com/editor/scene/1527496

Hi @OMN1B,

You can use clamp to limit a value, example code:

const angleY = pc.math.clamp(angleValue, -45, 45);

Now how that adapts to your code you will have to figure it out. You can take a look at the orbir-camera.js script in the model viewer starter project that does exactly that, limit the angle the camera can rotate with.

@Leonidas I know this is like 4 months later i took a break from game development but I implemented this into my code, my problem now is that when it hits that clamp, i think it still registers the rotation, so now when I look up, it will stop the camera from moving, but I still have to move the mouse as much as I moved it before being able to look anywhere else. It’s hard to explain so here’s my project. the code is in first-person-movement.js.
https://playcanvas.com/editor/scene/1509624
I’m also having another issue. when you look down, for some reason, it flips the camera around and makes everything really wonky until you look up again. (edit: second problem has been fixed)

Hey, I think that’s because you are rotating the camera twice in your code on line 94.

Try updating your logic to avoid that.

1 Like

I removed line 98 and 99(those were something i was trying earlier) but it’s still doing it