const PickerRaycast = pc.createScript("pickerRaycast");
PickerRaycast.prototype.initialize = function() {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.onSelect, this);
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onSelect, this);
PickerRaycast.prototype.onSelect = function(e) {
from = this.entity.camera.screenToWorld(
this.entity.camera.nearClip
to = this.entity.camera.screenToWorld(
this.entity.camera.farClip
from = this.entity.camera.screenToWorld(
this.entity.camera.nearClip
to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);
const result = this.app.systems.rigidbody.raycastFirst(from, to);
const pickedEntity = result.entity;
if (pickedEntity.name === "TouchableSpace") {
pickedEntity.script.createCoin.create(result.point);