I’m running a 2D project and am attempting to make a 2D square sprite (“Actor”) collide with another 2D square sprite (“Blocker”). However for some reason, the Actor gets blocked when too far away from the Blocker. It’s like there’s an invisible block in between, except there isn’t.
I’m suspecting it has to do with the Actor’s SCALE vs the SIZE of its own box collider. These two values are currently different, because I reduced the scale of the Actor (to 0.16,0.16) to make it better fitting to my camera screen size, while keeping the Box Collider size at (1,1).
I notice that if I reduce my box collider to (0.16, 0,16), the issue disappears. But then it looks really strange because the green outline of the box collider no longer wraps actual Actor (see image below).
What am I doing wrong here? I think I’m messing up the relationships between size, scale and camera size. Btw the camera is set on Size 1 / ortographic, if it makes a difference.
hit = Physics2D.BoxCast(transform.position, boxCollider.size, 0, new Vector2(0, moveDelta.y), Mathf.Abs(moveDelta.y * Time.deltaTime), LayerMask.GetMask("Actor", "Blocking"));
if (hit.collider == null)
{
transform.Translate(0, moveDelta.y * Time.deltaTime,0);
}
hit = Physics2D.BoxCast(transform.position, boxCollider.size, 0, new Vector2(moveDelta.x, 0), Mathf.Abs(moveDelta.x * Time.deltaTime), LayerMask.GetMask("Actor", "Blocking"));
if (hit.collider == null)
{
transform.Translate(moveDelta.x * Time.deltaTime, 0, 0);
}