I'm copying straight from the A-Frame documentation on RayCaster but I'm still not getting it right. I want the collider to occur when the camera connects with the cube.
Here's the github link for context.
<a-entity geometry="primitive: box" class="collidable"
position="1 2.5 0"></a-entity>
AFRAME.registerComponent('collider-check', {
dependencies: ['raycaster'],
init: function () {
this.el.addEventListener('raycaster-intersected', function () {
console.log('Player hit something!');
});
}
});
raycaster-intersected
event is a ray from camera to cursor position, if the ray hit something, it will triggerraycaster-intersected
event.collider
event is more like checking distance between camera and something collidable, you can look at this component sphere-collider.js then, register your owncollider-check
component.