Пример #1
0
    RayCastResult doGetValidMovement(Vector2 normal, float speed, params Vector2[] origins)
    {
        float dir = Mathf.Sign(speed);

        foreach (Vector2 v in origins)
        {
            RayCastResult r1 = doTryRaycast(v, speed, dir, normal);
            if (r1.isHit())
            {
                return(r1);
            }
        }
        return(RayCastResult.miss(speed));
    }
Пример #2
0
    private RayCastResult doTryRaycast(Vector2 origin, float speed, float dir, Vector2 normal)
    {
        RaycastHit2D hit = Physics2D.Raycast(origin, normal, Mathf.Abs(speed), layerMask);

        if (hit)
        {
            Debug.DrawRay(origin, normal * speed, Color.yellow);
            // Get Distance between entity and ground
            float distance = hit.fraction * Mathf.Abs(speed);
            // Stop entity's downward movement after coming within skin width of a boxCollider
            if (distance > skin)
            {
                return(RayCastResult.hit((distance * dir) + skin));
            }
            return(RayCastResult.hit(0));
        }
        Debug.DrawRay(origin, normal);
        return(RayCastResult.miss(speed));
    }