Parameters of Physics2D.BoxCast are unclear in the documentation
Looking at the documentation for BoxCast, it seems there are multiple ways to interpret the first two parameters origin
and size
. Notably, we could have
+------ size.x -------+
[origin] ------------------+ +
| | |
| | size.y (1)
| | |
+---------------------+ +
+------ size.x -------+
+---------------------+ +
| | |
| | size.y (2)
| | |
[origin]-------------------+ +
+- size.x -+
+---------------------+ +
| | |size.y
| [origin] | + (3)
| |
+---------------------+
So which one is it? For what it's worth, having the pivot of a 2D sprite character at its feet (so at the center bottom) seems to not align with the parameters of this function.
EDIT: it turns out this is the correct picture:
+------- size.x ------+
+---------------------+ +
| | |
| [origin] | size.y (4)
| | |
+---------------------+ +
Answer by MelvMay · Aug 30, 2016 at 12:05 PM
The origin of all shapes is the center point. Just like the BoxCollider2D defines the Box, you have a box of the specified size centered on the Origin.
This doesn't really answer the question. In any case, if you have a BoxCollider2D component, what will "Just Work" is to set the origin
to GetComponent<BoxCollider2D>().bounds.center
and the size
to GetComponent<BoxCollider2D>().bounds.size
.
A box centered on the origin of the specified size. How does this not answer your question?
None of your diagrams are correct. The origin is the center as per diagram (3) and the size is the full size of the box as per diagrams (2) + (3).
Your answer
Follow this Question
Related Questions
When friction on physic material 2d is at 0 my player slide 0 Answers
Different rigidbody2D not working together? 2 Answers
Uneven Jump Heights 1 Answer
Unity Overlap Point Causing Error 0 Answers