I am trying to cast a ray from my camera to a trigger volume and want to detect the collision with the trigger volume. Here is the script attached to my camera:
pc.script.create('picker_raycast', function (app) {
// Creates a new PickerRaycast instance
var PickerRaycast = function (entity) {
this.entity = entity;
};
PickerRaycast.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
app.mouse.on(pc.input.EVENT_MOUSEDOWN, this.onSelect, this);
},
onSelect: function (e) {
var from = this.entity.getPosition();
var to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);
app.systems.rigidbody.raycastFirst(from, to, function (result) {
var pickedEntity = result.entity;
//alert("boo"); This works! Someone should say in the tutorial that this needs to be applied to the camera!
}.bind(this));
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
return PickerRaycast;
});
Now on my trigger volume I have the following:
pc.script.create('test1', function (app) {
// Creates a new Test1 instance
var Test1 = function (entity) {
this.entity = entity;
};
Test1.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.entity.collision.on('contact', function (result) {
alert("finally");
});
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
}
};
return Test1;
});
I am not getting the “finally!” alert when I click on the trigger volume. I tried to follow the tutorial from here (http://answers.playcanvas.com/questions/102/how-do-i-implement-trigger-volumes-and-ray-casting) but I haven’t been successful. What am I doing wrong?