Unknown problem with click detection/raycasting code (unable to properly debug)

I’m working on a project right now, and I’m trying to add a basic weapons system, however I can’t figure out this raycasting code, and I have no way to debug (inspect element is disabled on my computer), so I need some help figuring out what’s going wrong here.

Problem: No cube appears where the player clicked
Intended result: Cube appears where the player clicked

Code:

Weapon.prototype.update = function(dt) {
    if (this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT)) {
        var result = this.app.systems.rigidbody.raycastFirst(this.entity.getPosition(),this.camera.camera.screenToWorld(screenX, screenY, this.camera.farClip));
        if (result) {
            var entity = new pc.Entity();
            entity.addComponent('render', {type: 'box'});
            this.app.root.addChild(entity);
            entity.setPosition(result.point);
        }
    }
};

Hi @The_J and welcome! Do you define screenX and screenY somewhere?

Nope, just realized this.
I can’t find where I can get these values though, do you know?

Normally this is coming from the mouse event. Please check the page below.

https://developer.playcanvas.com/en/user-manual/physics/ray-casting/

You can also check my example project, there I use the center of the screen for the raycast.

https://playcanvas.com/project/874243/overview/drag-and-drop