我试着做一个现实的洞,为一个游泳池游戏。我想要做的是找出一个球的中心是否与洞的形状(这也是一个圆)相交,所以把它算成盆栽。我可以用ball.position找到球的中心,但找不出它是否在洞形内的方法。我该怎么做?
发布于 2022-09-10 03:42:25
我不太擅长玩游戏,但不管怎么说,数学都是一样的。你要做的是检查球的中心和洞的中心之间的距离是否小于洞的半径。下面是一些伪代码作为示例:
# the standard (euclidian) distance formula
def distance(a, b):
return sqrt((b.x - a.x)**2 + (b.y - a.y)**2)
if distance(ball.pos, hole.pos) < hole.radius:
# the ball is inside the holehttps://stackoverflow.com/questions/73668952
复制相似问题