- Home /
HOW TO ONLY DETECT ANGLES BY COLLIDERS2D FACES
Explaining my question: I have an object that has 6 raycasts to detect angulations, they all start from the edges of that object as illustrated in the image.
they return to me the angle of the surface that they are colliding for me to detect what is soil and what is wall.
But it can happen that the boxcollider of this object of mine enters the ground a little and then the raycast is completely inside the collider without passing through any surface, in this case it returns me 90 angle, and vector 2 (1.0, 0.0) of normal.
there is some form for me to say that when inside a collider this angle is zero, or else just detect angulations on the faces of collider2d.
I really appreciate if anyone has any suggestions, it will help me a lot! thanks in advance!
Do you have a RigiBody attached to it ? Try setting the Collision Detection to Continuous first of all if it is not already. Also, when do you call the raycasts ? In the Update or FixedUpdate ?
Yes, I have a rigidbody attached with continuous detection, I also did the raycast call tests by FixedUpdate, and by Update, I also tried to change the physics update in the settings to Update but it didn't seem to have any effect. I think I just need to find a way to filter this condition.
What about checking the angle from the upper raycasts ? I guess they all return the same angle anyway ?
I’m checking all of them to detect collisions with walls, in case if the angle of any surface is greater than 60, that surface is recognized by the groundcheck as a wall and not soil, so I need verification on all raycasts, because if it happens to terrain is not high enough to reach the upper raycasts, so the lower ones detect it.
OK I understand where you're going with that. Would't it be more accurate and error proof to use something like this ? Then you calculate the angle between each hit points of the raycasts, and you're sure you never have false positive
Your answer
Follow this Question
Related Questions
How can i compare Text string from multiple child Text objects? 1 Answer
Is there a convenient way to check if two gameobjects are touching BUT NOT overlapping? 2 Answers
How can i shoot 2D ball/bounce of wall using Raycast? 1 Answer
Is there a way to only acces one collider when there are many colliders with the same tag? 1 Answer
Is my 2D Raycast set up correctly? because it does not seem to hit anything when i use a layer mask. 1 Answer