[SOLVED] How to move camera only on X and Z axis

I would like to create a camera movement controller similar to your orbit camera example. But in my case I want the camera to move only on the X and Z-axis independently from the camera entity forward vector.

I try to modify this part to convert the Y-axis value to Z but it’s going in the wrong direction based on camera pitch. What am I doing wrong? Could you please advise the right solution for this case?

MouseInput.prototype.pan = function(screenPoint) {
    var fromWorldPoint = MouseInput.fromWorldPoint;
    var toWorldPoint = MouseInput.toWorldPoint;
    var worldDiff = MouseInput.worldDiff;
    // For panning to work at any zoom level, we use screen point to world projection
    // to work out how far we need to pan the pivotEntity in world space 
    var camera = this.entity.camera;
    var distance = this.orbitCamera.distance;
    camera.screenToWorld(screenPoint.x, screenPoint.y, distance, fromWorldPoint);
    camera.screenToWorld(this.lastPoint.x, this.lastPoint.y, distance, toWorldPoint);

    worldDiff.sub2(toWorldPoint, fromWorldPoint);
    var distanceVec = new pc.Vec3(worldDiff.x, 0, worldDiff.y);

I’m not sure I understand what this would look like?

Would using the scroll wheel move the camera forward but only along the XZ plane and not toward the center of the screen?

Do you want to use pan at all in this case?

Thanks for the reply! I want something similar to this Matrix (matrixworld.org)

At the moment, the pan is effectively raycasting against a plane that is always facing the camera. What you would need to do instead is to use a plane along the XZ plane and raycast against that.

Example https://playcanvas.com/project/916401/overview/camera-pan-xz-plane

Your approach would also work but the worldDiff vector would need to be transformed into the same local space of the camera (with the modification that you want to ignore pitch)

I understand. Thanks a lot for your help. It is invaluable! My issue can be considered resolved.

Updated project for 1.62: https://playcanvas.com/project/916401/overview/camera-pan-xz-plane