Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Some problem relate to Boxcast2D

Discussion in '2D' started by dreamerPR, Mar 19, 2023.

  1. dreamerPR


    Nov 13, 2018
    I understand the distance is for define the distance of Boxcast that mean the one that use to define the direction is dir which is Vector2.down in this case. The problem is sometime when the character is near a wall. results give a hit.point that is on the opposite side of direction. The only case that is possible is because size.y of the boxcast. I think the hit.point is too far in this case tho.
    here the code
    Code (CSharp):
    1. Vector2 size = new Vector2(colliderSize.x, 0.001f);
    2.         Vector2 offset = new Vector2(0,  colliderSize.y * 0.5f);
    3.         Vector3 offset3 = offset;
    4.         Vector3 start = - offset3;
    5.         ExtDebug.DrawBoxCastBox(start, size, Quaternion.identity, Vector2.down, Vector2.Distance(start, des),;
    6.         RaycastHit2D[] results = Physics2D.BoxCastAll(start, size, 0, Vector2.down, Vector2.Distance(start, des), LayerMask.GetMask(TagAndLayer.tileMapLayer));
    image of the problem

    the axis show the position of hit.point. A red box show Boxcast2D area.

    unit y is start.y. hit y is hit.point.y