Exemplo n.º 1
0
    public static HitBarPoints GetBoundPoint(this BoxCollider boxCollider, Transform torso, LayerMask mask)
    {
        HitBarPoints bp       = new HitBarPoints();
        BoxPoint     boxPoint = boxCollider.GetBoxPoint();
        Ray          toTop    = new Ray(boxPoint.top, boxPoint.top - torso.position);
        Ray          toCenter = new Ray(torso.position, boxPoint.center - torso.position);
        Ray          toBottom = new Ray(torso.position, boxPoint.bottom - torso.position);

        Debug.DrawRay(toTop.origin, toTop.direction, Color.red, 2);
        Debug.DrawRay(toCenter.origin, toCenter.direction, Color.green, 2);
        Debug.DrawRay(toBottom.origin, toBottom.direction, Color.blue, 2);
        RaycastHit hit;
        float      dist = Vector3.Distance(torso.position, boxPoint.top);

        if (Physics.Raycast(toTop, out hit, dist, mask))
        {
            bp |= HitBarPoints.Top;
            Debug.Log(hit.transform.name);
        }
        dist = Vector3.Distance(torso.position, boxPoint.center);
        if (Physics.Raycast(toCenter, out hit, dist, mask))
        {
            bp |= HitBarPoints.Center;
            Debug.Log(hit.transform.name);
        }
        dist = Vector3.Distance(torso.position, boxPoint.bottom);
        if (Physics.Raycast(toBottom, out hit, dist, mask))
        {
            bp |= HitBarPoints.Bottom;
            Debug.Log(hit.transform.name);
        }

        return(bp);
    }
Exemplo n.º 2
0
    public static BoxPoint GetBoxPoint(this BoxCollider boxCollider)
    {
        BoxPoint bp = new BoxPoint();

        bp.center = boxCollider.transform.TransformPoint(boxCollider.center);
        var height = boxCollider.transform.lossyScale.y * boxCollider.size.y;
        var ray    = new Ray(bp.center, boxCollider.transform.up);

        bp.top    = ray.GetPoint((height * 0.5f));
        bp.bottom = ray.GetPoint(-(height * 0.5f));

        return(bp);
    }
Exemplo n.º 3
0
 private void Awake()
 {
     instance = this;
 }
Exemplo n.º 4
0
        public Vector3 GetBoxPoint(BoxPoint boxPoint)
        {
            Vector3 center  = Center;
            Vector3 extents = Extents;

            switch (boxPoint)
            {
            case BoxPoint.Center:

                return(center);

            case BoxPoint.FrontTopLeft:

                return(center - BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x +
                       BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z);

            case BoxPoint.FrontTopRight:

                return(center + BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x +
                       BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z);

            case BoxPoint.FrontBottomRight:

                return(center + BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x -
                       BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z);

            case BoxPoint.FrontBottomLeft:

                return(center - BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x -
                       BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z);

            case BoxPoint.BackTopLeft:

                return(center - BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x +
                       BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z);

            case BoxPoint.BackTopRight:

                return(center + BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x +
                       BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z);

            case BoxPoint.BackBottomRight:

                return(center + BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x -
                       BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z);

            case BoxPoint.BackBottomLeft:

                return(center - BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x -
                       BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y +
                       BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z);

            default:

                return(Vector3.zero);
            }
        }