Player is "super position"

I am developing a game called sticks & Stones, I made a custom player controller from one of the older examples, and recently added a dead zone to looking, now note: before the addition with the on mouse move function there was no issue with the player camera, you can see what I mean if you just look around in the game. Here is the launch. The first person movement script is here. I would appreciate any help that can fix this issue.

For a short explanation : anything under 1 to 0 is causing the issue (the second number value)

FirstPersonMovement.prototype._onMouseMove = function (e) {
    if (pc.Mouse.isPointerLocked() || e.buttons[0]) {
        this.eulers.x -= this.lookSpeed * e.dx;
        this.eulers.y -= this.lookSpeed * e.dy;

        // Ensure vertical rotation stays within constraints
        this.eulers.y = pc.math.clamp(this.eulers.y, -Math.PI / 0.04, Math.PI / 1); //at this 0.04 is the issue

        // Apply additional constraints for camera position
        var cameraWorldPos = this.camera.getPosition();
        if (cameraWorldPos.z > 118) {
            cameraWorldPos.z = 118;
        } else if (cameraWorldPos.z < -162) {
            cameraWorldPos.z = -162;
        }
        this.camera.setPosition(cameraWorldPos);
    }
};

I changed the values a bit so now it doesn’t give the weird camera position glitch, but you still can’t look all the way up. If anyone has any idea or way to fix this without the players camera switching between two positions I’d be happy to hear it. (edit: this did NOT fix the issue, after reviewing for the - z axis rotation I think anything less then 1 will not work due to the bugs that arise from it)

FirstPersonMovement.prototype._onMouseMove = function (e) {
    if (pc.Mouse.isPointerLocked() || e.buttons[0]) {
        this.eulers.x -= this.lookSpeed * e.dx;
        this.eulers.y -= this.lookSpeed * e.dy;

        // Ensure vertical rotation stays within constraints
        this.eulers.y = pc.math.clamp(this.eulers.y, -Math.PI / 0.04, Math.PI / 0.1); //edited values

        // Apply additional constraints for camera position
        var cameraWorldPos = this.camera.getPosition();
        if (cameraWorldPos.z > 120) {
            cameraWorldPos.z = 120; //rounded out 118 to 120
        } else if (cameraWorldPos.z < -180) {
            cameraWorldPos.z = -180; //edited clamp values (180)
        }
        this.camera.setPosition(cameraWorldPos);
    }
};

I don’t know what all the extra code is for maybe you are trying to add something in the future???

but you can just use a clamp for 90 and -90:

FirstPersonMovement.prototype._onMouseMove = function (event) {
    // Update camera yaw and pitch
    this.eulers.y -= event.dx * this.lookSpeed;
    this.eulers.x -= event.dy * this.lookSpeed;

    // Limit pitch to avoid flipping
    this.eulers.x = pc.math.clamp(this.eulers.x, -90, 90);

    // Update camera entity rotation
    this.camera.setEulerAngles(this.eulers.x, this.eulers.y, 0);
    
};
1 Like

Appreciate it, and no I wasn’t planning on anything else for clamping look view, I think maybe I mixed up some logic with the original code (first person controller) either it was the old or new one I am not too sure, I do appreciate the corrected function, thanks!

its all good

1 Like

z axis is up/down using mouse move to also set rotation and having so many issues right now. y is z for some reason, even though y should be left and right.

Is the camera rotated???

No actually. I set all my players rotations to 0 0 0.