- Home /
How to use Physics2D.OverlapArea
Hi,I dont know how get the points of the rectangle, i tried with this code, with erratic results.
void Update()
{
walled = Physics2D.overlapArea (player.position,-player.position,Platform);
}
in the Script reference says:
The rectangle is defined by two diagonally opposite corner coordinates in world space. You can think of these as top-left and bottom-right but the test will still work if the ordering of the points is reversed. How i get this points?.
Comment
Best Answer
Answer by ReContraChanfle · Apr 15, 2014 at 06:57 PM
fixed, i figured out, this its the solution:
Vector2 pointA;
Vector2 pointB;
void FixedUpdate()
{
pointA = stick.position //The position of the rectangle
pointB.x = stick.position.x + 0.25f; // sum the size of the axis X of the box collider
pointB.y = stick.position.y + 6.19f; // sum the size of the axis Y of the collider
walled = Physics2D.overlapArea (poinA,pointB,Platform);
}
Answer by Funtownarcade · Apr 15, 2014 at 08:33 AM
You can try something like transform.position.x - half its width and transform.position.y + its height for the points, or you could use the position of empty gameobjects that you make and put in place by hand.