# Three.js raycaster.intersectObjects fails (returns no results)

**URL:** <https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312>\
**Category:** Questions\
**Tags:** raycaster\
**Created:** [January 15, 2024, 4:45am UTC](https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312 "2024-01-15T04:45:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rene\_Veerman](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rene_veerman/32/16356_2.png) [@Rene\_Veerman](https://discourse.threejs.org/u/Rene_Veerman)\
**Post date:** [January 15, 2024, 4:45am UTC](https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312/1 "2024-01-15T04:45:08Z")

</div>

Hello everyone,

i’ve got a new filesystem + database data-editor in 2D and 3D in the works.  
it’s MIT-licensed. 🙂

but i’ve got a problem here : [NicerApp-WebOS-v6.y.z/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js at 9e4de165f077be0f5764b55e427f00fff7946efe · NicerEnterprises/NicerApp-WebOS-v6.y.z · GitHub](https://github.com/NicerEnterprises/NicerApp-WebOS-v6.y.z/blob/9e4de165f077be0f5764b55e427f00fff7946efe/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js#L657) - var intersects2 stays empty

the live demo is at [NicerApp WebOS Unified Interface](https://new.nicer.app/mediaPlayer)  
and the latest sources are at [GitHub - NicerEnterprises/NicerApp-WebOS-v6.y.z](https://github.com/NicerEnterprises/NicerApp-WebOS-v6.y.z)

i’ve spent the last 2.5 days completely stuck on this issue, and i’d love to receive some help.  
i promise to credit the tip giver with a link back to this thread here.

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [January 15, 2024, 5:39am UTC](https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312/2 "2024-01-15T05:39:30Z")

</div>

1. Consider using meaningful names in code - currently it’s pretty much impossible to understand or debug it. With names like `t`, `s2` etc. it’s becoming hard to indicate the purpose of specific variables.
2. In any code besides short and simple JS scripts, avoid using `vars` - especially in the way you’ve used them [in places like this](https://github.com/NicerEnterprises/NicerApp-WebOS-v6.y.z/blob/9e4de165f077be0f5764b55e427f00fff7946efe/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js#L622) - this, and all other, vars are moved to the top of the current (usually function / class, not the closest `if` or `{` ) context and are very likely to collide at some point. Use `const` instead.
3. As for the raycasting, try setting [the second parameter](https://threejs.org/docs/index.html?q=raycas#api/en/core/Raycaster.intersectObjects) of intersectObjects to `true`.

---

<div class="post-metadata">

**Author:** ![Rene\_Veerman](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rene_veerman/32/16356_2.png) [@Rene\_Veerman](https://discourse.threejs.org/u/Rene_Veerman)\
**Post date:** [January 15, 2024, 6:04am UTC](https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312/3 "2024-01-15T06:04:19Z")

</div>

t.s2 contains all the Mesh objects, as a flat list. it’s linked to t.items; t.items[1].model === t.s2[1] and t.s2[1].it points back to t.items[1].

var t is the current js class object; an abbreviation of ‘this’.

and giving intersectObjects a 2nd param of ‘true’, doesn’t fix this problem ☹

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [January 15, 2024, 7:15am UTC](https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312/4 "2024-01-15T07:15:49Z")

</div>

Even with partial explanations of what `s2` is, there’s still no way to debug this code. It’s unformatted and uses `vars` all over the place 🥲

If setting recursive parameter to true didn’t work - then anything could be at fault. Console.log value of the objects you’re trying to intersect and the ray - see if these values make sense (raycasting is independent of rendering and visibility - so as long as you pass a properly pointing ray and an array of valid `Three.Mesh` objects, it should work ok.)

(Side-note: If you’re working with classes of 2000+ lines, and now you mention you store arrays of circular dependencies, you pretty much are not allowed to not use [typescript](https://www.typescriptlang.org/).)

---

<div class="post-metadata">

**Author:** ![Rene\_Veerman](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rene_veerman/32/16356_2.png) [@Rene\_Veerman](https://discourse.threejs.org/u/Rene_Veerman)\
**Post date:** [January 15, 2024, 7:34am UTC](https://discourse.threejs.org/t/three-js-raycaster-intersectobjects-fails-returns-no-results/60312/5 "2024-01-15T07:34:55Z")

</div>

hi again 🙂

i’ve fixed the problem.

> <https://github.com/NicerEnterprises/NicerApp-WebOS-v6.y.z/blob/2546b37ff02d909c9fc545cabb6e04f3a59066fb/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js#L757>

> <https://github.com/NicerEnterprises/NicerApp-WebOS-v6.y.z/blob/2546b37ff02d909c9fc545cabb6e04f3a59066fb/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js#L687>

> <https://github.com/NicerEnterprises/NicerApp-WebOS-v6.y.z/blob/2546b37ff02d909c9fc545cabb6e04f3a59066fb/NicerAppWebOS/logic.vividUserInterface/v6.y.z/3D/na3D.js#L625>

and ‘var’ has a limited scope conditions set, ‘const’ is readonly and way too strict for my liking…  
i do work a lot with large classes, my universal web theme editor that comes with my software is atm 2610 lines long. i have a small bunch of files like that. around a dozen.
