AFRAME raytrace get reference of intersected entity











up vote
0
down vote

favorite












I got a raycaster component attached to the vr controller entity:



 <a-entity id="righthand" 
vive-controls="hand: right; "
oculus-touch-controls="hand: right;"
controls-ui
collider-check
>
<a-entity raycaster="objects: .collidable; showLine: true; far: 100; " line="color: blue; opacity: 0.5" ></a-entity>

</a-entity>


and I got an entity in the scene that will receive the raytrace events:



<a-entity id='myCube' class="collidable" position="0 1.25 -6"  obj-model="obj: #cube-obj; mtl: #cube-mtl" >
</a-entity>


How do I get the id or any reference of the collided entity in the 'raycaster-intersected' event?
I tried the following code, and nothing seems to contains this data:



AFRAME.registerComponent('collider-check', {
dependencies: ['raycaster'],

init: function () {
this.el.addEventListener('raycaster-intersected', function (evt) {

console.log(evt.detail.el); // not here

console.log(evt.detail.intersection); // not here

console.log(evt.detail);// not here

console.log('Player hit something!');
});
}
});


Thanks in advance.



---------Update-----------



@Piotr Adam Milewski answer is correct. The event to be listening is raycaster-intersection instead of raycaster-intersected. In that way you can loop an array of the intersected entities.



Is it possible to get the same result from raycaster-intersected ?? If that event is emitted on the intersected entity, then It should be possible to get its id and other properties.I dont think is ideal to loop over an array every time an intersection event occurs.










share|improve this question
























  • i've added a solution using the event on the target
    – Piotr Adam Milewski
    Nov 21 at 20:45










  • Yeah, now it works. Maybe Aframe documentation should mention all this.
    – Camilo
    Nov 21 at 21:17










  • Your collider-check should be attached to the raycaster. The code above now has two raycasdters.
    – ngokevin
    Nov 21 at 22:27















up vote
0
down vote

favorite












I got a raycaster component attached to the vr controller entity:



 <a-entity id="righthand" 
vive-controls="hand: right; "
oculus-touch-controls="hand: right;"
controls-ui
collider-check
>
<a-entity raycaster="objects: .collidable; showLine: true; far: 100; " line="color: blue; opacity: 0.5" ></a-entity>

</a-entity>


and I got an entity in the scene that will receive the raytrace events:



<a-entity id='myCube' class="collidable" position="0 1.25 -6"  obj-model="obj: #cube-obj; mtl: #cube-mtl" >
</a-entity>


How do I get the id or any reference of the collided entity in the 'raycaster-intersected' event?
I tried the following code, and nothing seems to contains this data:



AFRAME.registerComponent('collider-check', {
dependencies: ['raycaster'],

init: function () {
this.el.addEventListener('raycaster-intersected', function (evt) {

console.log(evt.detail.el); // not here

console.log(evt.detail.intersection); // not here

console.log(evt.detail);// not here

console.log('Player hit something!');
});
}
});


Thanks in advance.



---------Update-----------



@Piotr Adam Milewski answer is correct. The event to be listening is raycaster-intersection instead of raycaster-intersected. In that way you can loop an array of the intersected entities.



Is it possible to get the same result from raycaster-intersected ?? If that event is emitted on the intersected entity, then It should be possible to get its id and other properties.I dont think is ideal to loop over an array every time an intersection event occurs.










share|improve this question
























  • i've added a solution using the event on the target
    – Piotr Adam Milewski
    Nov 21 at 20:45










  • Yeah, now it works. Maybe Aframe documentation should mention all this.
    – Camilo
    Nov 21 at 21:17










  • Your collider-check should be attached to the raycaster. The code above now has two raycasdters.
    – ngokevin
    Nov 21 at 22:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I got a raycaster component attached to the vr controller entity:



 <a-entity id="righthand" 
vive-controls="hand: right; "
oculus-touch-controls="hand: right;"
controls-ui
collider-check
>
<a-entity raycaster="objects: .collidable; showLine: true; far: 100; " line="color: blue; opacity: 0.5" ></a-entity>

</a-entity>


and I got an entity in the scene that will receive the raytrace events:



<a-entity id='myCube' class="collidable" position="0 1.25 -6"  obj-model="obj: #cube-obj; mtl: #cube-mtl" >
</a-entity>


How do I get the id or any reference of the collided entity in the 'raycaster-intersected' event?
I tried the following code, and nothing seems to contains this data:



AFRAME.registerComponent('collider-check', {
dependencies: ['raycaster'],

init: function () {
this.el.addEventListener('raycaster-intersected', function (evt) {

console.log(evt.detail.el); // not here

console.log(evt.detail.intersection); // not here

console.log(evt.detail);// not here

console.log('Player hit something!');
});
}
});


Thanks in advance.



---------Update-----------



@Piotr Adam Milewski answer is correct. The event to be listening is raycaster-intersection instead of raycaster-intersected. In that way you can loop an array of the intersected entities.



Is it possible to get the same result from raycaster-intersected ?? If that event is emitted on the intersected entity, then It should be possible to get its id and other properties.I dont think is ideal to loop over an array every time an intersection event occurs.










share|improve this question















I got a raycaster component attached to the vr controller entity:



 <a-entity id="righthand" 
vive-controls="hand: right; "
oculus-touch-controls="hand: right;"
controls-ui
collider-check
>
<a-entity raycaster="objects: .collidable; showLine: true; far: 100; " line="color: blue; opacity: 0.5" ></a-entity>

</a-entity>


and I got an entity in the scene that will receive the raytrace events:



<a-entity id='myCube' class="collidable" position="0 1.25 -6"  obj-model="obj: #cube-obj; mtl: #cube-mtl" >
</a-entity>


How do I get the id or any reference of the collided entity in the 'raycaster-intersected' event?
I tried the following code, and nothing seems to contains this data:



AFRAME.registerComponent('collider-check', {
dependencies: ['raycaster'],

init: function () {
this.el.addEventListener('raycaster-intersected', function (evt) {

console.log(evt.detail.el); // not here

console.log(evt.detail.intersection); // not here

console.log(evt.detail);// not here

console.log('Player hit something!');
});
}
});


Thanks in advance.



---------Update-----------



@Piotr Adam Milewski answer is correct. The event to be listening is raycaster-intersection instead of raycaster-intersected. In that way you can loop an array of the intersected entities.



Is it possible to get the same result from raycaster-intersected ?? If that event is emitted on the intersected entity, then It should be possible to get its id and other properties.I dont think is ideal to loop over an array every time an intersection event occurs.







javascript aframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 19:32

























asked Nov 21 at 17:12









Camilo

12510




12510












  • i've added a solution using the event on the target
    – Piotr Adam Milewski
    Nov 21 at 20:45










  • Yeah, now it works. Maybe Aframe documentation should mention all this.
    – Camilo
    Nov 21 at 21:17










  • Your collider-check should be attached to the raycaster. The code above now has two raycasdters.
    – ngokevin
    Nov 21 at 22:27


















  • i've added a solution using the event on the target
    – Piotr Adam Milewski
    Nov 21 at 20:45










  • Yeah, now it works. Maybe Aframe documentation should mention all this.
    – Camilo
    Nov 21 at 21:17










  • Your collider-check should be attached to the raycaster. The code above now has two raycasdters.
    – ngokevin
    Nov 21 at 22:27
















i've added a solution using the event on the target
– Piotr Adam Milewski
Nov 21 at 20:45




i've added a solution using the event on the target
– Piotr Adam Milewski
Nov 21 at 20:45












Yeah, now it works. Maybe Aframe documentation should mention all this.
– Camilo
Nov 21 at 21:17




Yeah, now it works. Maybe Aframe documentation should mention all this.
– Camilo
Nov 21 at 21:17












Your collider-check should be attached to the raycaster. The code above now has two raycasdters.
– ngokevin
Nov 21 at 22:27




Your collider-check should be attached to the raycaster. The code above now has two raycasdters.
– ngokevin
Nov 21 at 22:27












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










From the docs:





  • raycaster-intersected is emitted on the intersected entity. It contains info about the raycasting entity and the intersection details.


  • raycaster-intersection is emitted on the raycasting entity, and contains a list of intersected entities.


When using raycaster-intersection try accessing evt.detail.els for an array of intersected entities. Example here





Since the raycaster-intersected is emitted on the intersected entity, you can detect whether the raycaster touched your target.



target.addEventListener('raycaster-intersected', (e)=> { 
// intersected, e.target contains the element
// e.detail.getIntersection(e.target) contains info about the intersection
})


Fiddle here. Fiddle with getIntersection() here.






share|improve this answer























  • I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
    – Camilo
    Nov 21 at 18:37












  • ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
    – Piotr Adam Milewski
    Nov 21 at 18:40










  • I updated my question.
    – Camilo
    Nov 21 at 19:34










  • Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
    – ngokevin
    Nov 21 at 22:27










  • @ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
    – Piotr Adam Milewski
    Nov 21 at 22:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417344%2faframe-raytrace-get-reference-of-intersected-entity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










From the docs:





  • raycaster-intersected is emitted on the intersected entity. It contains info about the raycasting entity and the intersection details.


  • raycaster-intersection is emitted on the raycasting entity, and contains a list of intersected entities.


When using raycaster-intersection try accessing evt.detail.els for an array of intersected entities. Example here





Since the raycaster-intersected is emitted on the intersected entity, you can detect whether the raycaster touched your target.



target.addEventListener('raycaster-intersected', (e)=> { 
// intersected, e.target contains the element
// e.detail.getIntersection(e.target) contains info about the intersection
})


Fiddle here. Fiddle with getIntersection() here.






share|improve this answer























  • I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
    – Camilo
    Nov 21 at 18:37












  • ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
    – Piotr Adam Milewski
    Nov 21 at 18:40










  • I updated my question.
    – Camilo
    Nov 21 at 19:34










  • Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
    – ngokevin
    Nov 21 at 22:27










  • @ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
    – Piotr Adam Milewski
    Nov 21 at 22:50















up vote
2
down vote



accepted










From the docs:





  • raycaster-intersected is emitted on the intersected entity. It contains info about the raycasting entity and the intersection details.


  • raycaster-intersection is emitted on the raycasting entity, and contains a list of intersected entities.


When using raycaster-intersection try accessing evt.detail.els for an array of intersected entities. Example here





Since the raycaster-intersected is emitted on the intersected entity, you can detect whether the raycaster touched your target.



target.addEventListener('raycaster-intersected', (e)=> { 
// intersected, e.target contains the element
// e.detail.getIntersection(e.target) contains info about the intersection
})


Fiddle here. Fiddle with getIntersection() here.






share|improve this answer























  • I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
    – Camilo
    Nov 21 at 18:37












  • ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
    – Piotr Adam Milewski
    Nov 21 at 18:40










  • I updated my question.
    – Camilo
    Nov 21 at 19:34










  • Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
    – ngokevin
    Nov 21 at 22:27










  • @ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
    – Piotr Adam Milewski
    Nov 21 at 22:50













up vote
2
down vote



accepted







up vote
2
down vote



accepted






From the docs:





  • raycaster-intersected is emitted on the intersected entity. It contains info about the raycasting entity and the intersection details.


  • raycaster-intersection is emitted on the raycasting entity, and contains a list of intersected entities.


When using raycaster-intersection try accessing evt.detail.els for an array of intersected entities. Example here





Since the raycaster-intersected is emitted on the intersected entity, you can detect whether the raycaster touched your target.



target.addEventListener('raycaster-intersected', (e)=> { 
// intersected, e.target contains the element
// e.detail.getIntersection(e.target) contains info about the intersection
})


Fiddle here. Fiddle with getIntersection() here.






share|improve this answer














From the docs:





  • raycaster-intersected is emitted on the intersected entity. It contains info about the raycasting entity and the intersection details.


  • raycaster-intersection is emitted on the raycasting entity, and contains a list of intersected entities.


When using raycaster-intersection try accessing evt.detail.els for an array of intersected entities. Example here





Since the raycaster-intersected is emitted on the intersected entity, you can detect whether the raycaster touched your target.



target.addEventListener('raycaster-intersected', (e)=> { 
// intersected, e.target contains the element
// e.detail.getIntersection(e.target) contains info about the intersection
})


Fiddle here. Fiddle with getIntersection() here.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 22:46

























answered Nov 21 at 18:24









Piotr Adam Milewski

5,03721025




5,03721025












  • I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
    – Camilo
    Nov 21 at 18:37












  • ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
    – Piotr Adam Milewski
    Nov 21 at 18:40










  • I updated my question.
    – Camilo
    Nov 21 at 19:34










  • Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
    – ngokevin
    Nov 21 at 22:27










  • @ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
    – Piotr Adam Milewski
    Nov 21 at 22:50


















  • I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
    – Camilo
    Nov 21 at 18:37












  • ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
    – Piotr Adam Milewski
    Nov 21 at 18:40










  • I updated my question.
    – Camilo
    Nov 21 at 19:34










  • Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
    – ngokevin
    Nov 21 at 22:27










  • @ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
    – Piotr Adam Milewski
    Nov 21 at 22:50
















I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
– Camilo
Nov 21 at 18:37






I'm getting this error: e.detail.getIntersection is not a function. I tried evt.detail.el.components.raycaster.getIntersection(this.el) but is null. If it helps I am using aframe.io/releases/0.8.2/aframe.min.js.
– Camilo
Nov 21 at 18:37














ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
– Piotr Adam Milewski
Nov 21 at 18:40




ngoKevin mentioned it here, it seems to be implemented on the master branch but i'm also getting nulls out of it, so i've updated the anwser (+fiddle).
– Piotr Adam Milewski
Nov 21 at 18:40












I updated my question.
– Camilo
Nov 21 at 19:34




I updated my question.
– Camilo
Nov 21 at 19:34












Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
– ngokevin
Nov 21 at 22:27




Shouldn't the code say raycaster-intersected? getIntersection need to pass in the intersected entity, not raycaster entity.
– ngokevin
Nov 21 at 22:27












@ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
– Piotr Adam Milewski
Nov 21 at 22:50




@ngokevin thanks it was a typo, i'm not sure why it didn't work earlier, but i've updated my anwser with getIntersection and a fiddle.
– Piotr Adam Milewski
Nov 21 at 22:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417344%2faframe-raytrace-get-reference-of-intersected-entity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)