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.
javascript aframe
add a comment |
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.
javascript aframe
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
add a comment |
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.
javascript aframe
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
javascript aframe
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
add a comment |
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
add a comment |
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.
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 sayraycaster-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 withgetIntersection
and a fiddle.
– Piotr Adam Milewski
Nov 21 at 22:50
|
show 1 more comment
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.
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 sayraycaster-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 withgetIntersection
and a fiddle.
– Piotr Adam Milewski
Nov 21 at 22:50
|
show 1 more comment
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.
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 sayraycaster-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 withgetIntersection
and a fiddle.
– Piotr Adam Milewski
Nov 21 at 22:50
|
show 1 more comment
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.
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.
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 sayraycaster-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 withgetIntersection
and a fiddle.
– Piotr Adam Milewski
Nov 21 at 22:50
|
show 1 more comment
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 sayraycaster-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 withgetIntersection
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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