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);
}
}
};