- Home /
BoxCast, OverlapArea, and Raycasting; ground detection questions
The first question I have is what do each of the parameters of the Physics2D.Boxcast
? They don't really make sense. Size and distance? Direction and angle? Can the box be a rectangle? They reason why I bring up Boxcast
is because I am having one small bug with ground detection. To detect ground, I use two raycasts that are .1 units, and come from the bottom corners of my characters. The green squares are grounded and the red squares are not.
As you can see from the diagram everything functions as it should except for the middle square. It is on the ground, but the way I test for it does not know that it is on the ground. Using OverlapArea
or Boxcast
(if it works like I think it does) should resolve this problem but are they the most economical? Is OverlapArea
better than Boxcast
or vice versa? Two raycasts are for sure better than OverlapArea
and Boxcast
, but they do not cover every option. How do you guys deal with ground collision and which way uses the least amount of resources while covering every case?
Edit 1: A problem with OverlapArea
is that say your bounds are from -1 to 1, touching a wall will register you player as on the ground. Although a minute detail, it can be easily be fixed by adjusting the bounds of OverlapArea
by .1 on each side, but that could cause some problems if the character is on the very edge of a ledge.
Your answer
Follow this Question
Related Questions
How to do a raycast to make my player unable to move through certain objects? 2 Answers
My Raycasts seem to sometimes miss 0 Answers
Having problems with 2d collision triggers (javascript) 1 Answer
Getting a character to fly(follow cursor in 2D) in Unity4.3 0 Answers
help with scripting combo points 1 Answer