- Home /
isTouching() with multiple colliders
I created a 2D Game with Tilebased Movement. To check if there is a wall next to my character I have 4 colliders floating next to it and I'm using isTouching to check for Collisions. But I happen to use about 8 different Colliders now and it's not an option anymore to check for each of them with and OR connection?
Is there a way to check for isTouching(all collider/any collider) or should I switch to raycasts?
I just found a way to do this with raycasts "Physics2D.Raycast(playerPosition + Vector3.down, new Vector3(0, 0, -1))" would be my code for checking below the character, but my question still remains ^-^
You can use a straight raycast combined with a physics.overlapsphere since a single raycast will only return one collider at a time you can cast the raycast to check for a hit then overlapsphere from that point to check all the colliders in that area, if you wanted you can see if the colliders overlap by using the collider.bounds.intersects() just an idea.
Switch to raycast, its way faster then a bunch of colliders.
Your answer
Follow this Question
Related Questions
Make Character Controller a Box? 2 Answers
Collision detection not working properly with 2D sprites 1 Answer
Character controller collision 2 Answers
No Collision in 2d Scene 0 Answers