screenToWorld - Can't get identical to cursor movement

Hey everyone, I’m working on coding a camera pan, and I’ve run into an issue where I can’t synchronize the camera and cursor movements smoothly in 3D space. The cursor seems to move more quickly than the camera. Any suggestions?

var CameraPan = pc.createScript('cameraPan');

CameraPan.prototype.initialize = function() {
    this.isDragging = false;

    this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
    this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this); 
    this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
};

CameraPan.prototype.onMouseMove = function(event) {
    if (this.isDragging) {

        var screenPos = this.entity.camera.screenToWorld(event.x, event.y, 10, new pc.Vec3());
        var lastScreenPos = this.entity.camera.screenToWorld(this.lastMousePos.x, this.lastMousePos.y, 10, new pc.Vec3());

        var worldDelta = screenPos.sub(lastScreenPos);
        worldDelta.scale(-1);
        worldDelta.y = 0;

        this.entity.setPosition(this.entity.getPosition().add(worldDelta));

        this.lastMousePos.set(event.x, event.y);
     //   this.entity.camera.screenToWorld(event.x, event.y, 10, this.entity.getPosition());
    }
};

CameraPan.prototype.onMouseDown = function(event) {
    this.isDragging = true;
    this.lastMousePos = new pc.Vec2(event.x, event.y);
};

CameraPan.prototype.onMouseUp = function() {
    this.isDragging = false;
};

Top down view
Camera = y 10
plane y = 0

Could you explain in words, what you want to achieve with this line?

It doesn’t do anything, please ignore it :sweat_smile: