我有一个关于交叉路口或更确切地说是有条件的碰撞检测的问题。我正在做一个条(图像)和一个球(图像)之间的碰撞检测。可以根据用户对拖动条的响应上下移动条。碰撞检测代码如下。
public bool Intersects(Rect barRectangle, Rect blueBallRectangle)
{
barRectangle.Intersect(blueBallRectangle);
if (barRectangle.IsEmpty)
{
return false;
}
else
{
return true;
}
}
在私有 void OnUpdate(object sender, object e)
Rect blueBallRectangle= new Rect(blueBallPositionX, blueBallPositionY, blueBall.ActualWidth, blueBall.ActualHeight);
Rect barRectangle= new Rect(barPositionX, barPositionY, bar.ActualWidth, bar.ActualHeight);
目前,当球检测到碰撞时,它会偏转离开。但是,我想补充一点,它会通过间隙而不是偏转。
if (Intersects(barRectangle, blueBallRectangle))
{
this.blueBallVelocityY *= -1;
this.blueBallVelocityX *= -1;
}
酒吧的形象如下。