示例#1
0
 public bool isGrounded()
 {
     if (rDown == null)
     {
         return(true);
     }
     return(rDown.isHit());
 }
示例#2
0
 public float getValidMovementY(float orSmallerInput)
 {
     if (orSmallerInput > 0)
     {
         if (rUp == null)
         {
             Debug.Log("rUp is null");
             return(orSmallerInput);
         }
         if (rUp.isHit())
         {
             return(rUp.getAllowableSpeed());
         }
         return(orSmallerInput);
     }
     if (rDown == null)
     {
         Debug.Log("rDown is null");
         return(orSmallerInput);
     }
     if (rDown.isHit())
     {
         return(rDown.getAllowableSpeed());
     }
     return(orSmallerInput);
 }
示例#3
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));
    }
示例#4
0
    public void FixedUpdate(SpeedProvider chrc)
    {
        if (layerMask < 0)
        {
            layerMask = 1 << LayerMask.NameToLayer("Ground");
            if (layerMask < 0)
            {
                return;
            }
        }
        Vector2 c       = chrc.getCenter();
        float   speedX  = chrc.getSpeedX();
        float   speedY  = chrc.getSpeedY();
        Vector2 normalX = new Vector2(Mathf.Sign(speedX), 0);
        Vector2 normalY = new Vector2(0, Mathf.Sign(speedY));

        if (chrc.isRightFacing())
        {
            rUp   = doGetValidMovement(normalY, speedY, getTopLeftPlusDelta(c), getTopMiddle(c), getTopRightMinusDelta(c));
            rDown = doGetValidMovement(normalY, speedY, getBotLeftPlusDelta(c), getBotMiddle(c), getBotRightMinusDelta(c));
        }
        else
        {
            rUp   = doGetValidMovement(normalY, speedY, getTopRightMinusDelta(c), getTopMiddle(c), getTopLeftPlusDelta(c));
            rDown = doGetValidMovement(normalY, speedY, getBotRightMinusDelta(c), getBotMiddle(c), getBotLeftPlusDelta(c));
        }
        if (speedX > 0)
        {
            if (isGrounded())
            {
                rX = doGetValidMovement(normalX, speedX, getTopRight(c), getRight(c), getLowRight(c));
            }
            else
            {
                rX = doGetValidMovement(normalX, speedX, getTopRight(c), getRight(c), getBotRight(c));
            }
            if (rX.isHit())
            {
                rightBlocked = true;
            }
            else
            {
                rightBlocked = false;
            }
        }
        else
        {
            if (isGrounded())
            {
                rX = doGetValidMovement(normalX, speedX, getTopLeft(c), getLeft(c), getLowLeft(c));
            }
            else
            {
                rX = doGetValidMovement(normalX, speedX, getTopLeft(c), getLeft(c), getBotLeft(c));
            }
            if (rX.isHit())
            {
                leftBlocked = true;
            }
            else
            {
                leftBlocked = false;
            }
        }
    }