[SOLVED] First Person camera clamp question

I’m attempting to clamp the cameras rotation so it can not go 360 degrees. Am i even doing it right? I’m trying to modify the first person camera code.

Also second question, when it spawns the camera it is facing my characters face instead of away from the face. Is there a way to tell the camera which direction to face on spawning in?

FirstPersonMovement.prototype._createCamera = function () {
    // If user hasn't assigned a camera, create a new one
    this.camera = new pc.Entity();
    this.camera.setName("First Person Camera");
    this.camera.translateLocal(0, 1.6, 0.3);
    this.eulers.y = pc.math.clamp(this.eulers.y, -60, 60);
    this.eulers.x = pc.math.clamp(this.eulers.x, -60, 60);

Uh, I don’t know how to solve this problem but my coder @Fus_ion might help!

Hi @Aaron_B,

Yes your code looks correct, it should work if you are using this.eulers for rotating the camera.

The easiest way to solve the facing issue I’d say is rotate 180 degrees your character model. That way they will both look at the same direction.


@Leonidas In short, it’s not working. When i play test it simply continues to be able to rotate all 360degrees.

Ok i will simply rotate the model.

@Gabriel_Dobrzynski thanks i would love some help/insight.

this.eulers.y = pc.math.clamp(this.eulers.y, -60, 60);
this.eulers.x = pc.math.clamp(this.eulers.x, -60, 60);

Is this in the update loop or the mouse move callback?

Looking at the surrounding code, it looks like it is only called the once in the initialise function which means that the values aren’t being clamped when the app is running.


@Yaustar SOLVED: That worked putting it in the update. Rotating the model worked correctly as well.