# Problems with Raycasting and Sphere overlap

**URL:** <https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606>\
**Category:** 🌵 Needle Engine\
**Tags:** question\
**Created:** [March 16, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606 "2023-03-16T00:00:00Z")\
**Posts on this page:** 10\
**Page:** 3

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [March 23, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/41 "2023-03-23T00:00:00Z")

</div>

Yes the colliders have it. You can add it on the stair colliders too maybe (or the capsule should work), i think you can configure to physics material to use the max value always

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [March 23, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/42 "2023-03-23T00:00:00Z")

</div>

I will do some testing and get back, I did try adding that capsule collider with a 100 friction material but the character is unafected. Will try adding it on the stairs instead.

_by user 326444095130042368_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [March 24, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/43 "2023-03-24T00:00:00Z")

</div>

hello there, I am yet to try adding that physics material but in the meantime I have encounter another issue (I think)

So I am creating some raycastOptions to use the layer #3 and despite this it will still collide and detect only against layer 0 (the default one on Unity)

[https://cdn.discordapp.com/attachments/1085614900312821820/1088508219120422983/raycastProblems.mp4?ex=65d77e46&is=65c50946&hm=a0b03a9edccbc304f50d34c7552884754918e341f580b8c0275930c25b519dc2&(image larger than 4 MB)](https://cdn.discordapp.com/attachments/1085614900312821820/1088508219120422983/raycastProblems.mp4?ex=65d77e46&is=65c50946&hm=a0b03a9edccbc304f50d34c7552884754918e341f580b8c0275930c25b519dc2&)

_by user 326444095130042368_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [March 24, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/44 "2023-03-24T00:00:00Z")

</div>

should the layer options be setup on a different manner?

_by user 326444095130042368_

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [March 24, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/45 "2023-03-24T00:00:00Z")

</div>

Hi @Orlando Almario I will check it, it should work similarly.

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [March 24, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/46 "2023-03-24T00:00:00Z")

</div>

Ok the `layerMask`option is a bit raw. It is expecting the value of the layermask OR a full threejs `Layers`

Here is one way you can do it:

```ts
export class RaycastTest extends Behaviour {

    private _layers: Layers = new Layers();

    update(): void {
        if (this.context.input.getPointerDown(0)) {
            const rc = new RaycastOptions();
            rc.layerMask = this._layers;
            rc.layerMask.set(4);
            const hits = this.context.physics.raycast(rc);
            if (hits.length) {
                console.log(hits[0].object.name)
            }
            else console.log("no hits")
        }
    }

}

```

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [March 27, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/47 "2023-03-27T00:00:00Z")

</div>

ohh that is interesting, yeah I will try to do it this way. Maybe this could be a documentation update I could make a PR for that if possible

_by user 326444095130042368_

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [March 27, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/48 "2023-03-27T00:00:00Z")

</div>

I’ve updated a simplified api for that for the next version 🙂

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [March 27, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/49 "2023-03-27T00:00:00Z")

</div>

`rc.setLayer(4)`

---

<div class="post-metadata">

**Author:** ![Marcel\_Wiessler1](https://forum.needle.tools/user_avatar/forum.needle.tools/marcel_wiessler1/32/21_2.png) [@Marcel\_Wiessler1](https://forum.needle.tools/u/Marcel_Wiessler1)\
**Post date:** [March 27, 2023, 12:00am UTC](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606/50 "2023-03-27T00:00:00Z")

</div>

to use it like you wanted to with the layer index

[Previous page](https://forum.needle.tools/t/problems-with-raycasting-and-sphere-overlap/606.md?page=2)
