Racket.TestCollision C# (CSharp) Method

TestCollision() public method

public TestCollision ( Vector2 p, float radius ) : bool
p Vector2
radius float
return bool
    public bool TestCollision(Vector2 p, float radius)
    {
        if (!isValid)
        {
            return false;
        }
        var rx = Mathf.Clamp(x * pongpector.width, width / 2 + 1, pongpector.width - width / 2 - 1);
        var w = width + radius * 2;
        var h = height + radius * 2;
        var rect = new Rect(rx - (w / 2), y - (h / 2), w, h);
        return rect.Contains(p);
    }
}

Usage Example

示例#1
0
 public bool TestRacketCollision(Vector2 pos, Vector2 vel, float radius)
 {
     if (vel.y > 0)
     {
         return(bottomRacket.TestCollision(pos, radius));
     }
     else
     {
         return(topRacket.TestCollision(pos, radius));
     }
 }