如圖一個經典的乒乓球小游戲,我使用最常用的檢測球與球拍碰撞的公式發現當球速很快的時候,乒乓球有可能會miss掉球拍,從而造成一方扣分,為了不miss掉球拍,我試過使用intersect,就是給球和球拍加一個邊緣盒子,如果盒子交錯了,就表示碰撞了,但是代碼實測后發現還是會存在球miss球拍的情況,有沒有大神能給點思路,下面是那個常用的碰撞檢測的代碼,我現在的想法是能不能吧長方形的球拍變成長方體,但是不知道怎么實作

、、、
private bool CollisionOccurred()
{
// assume no collision
bool retval = false;
// heading towards player one
if (m_ball.DX < 0)
{
Rectangle b = m_ball.Rect;
Rectangle p = m_paddle1.Rect;
retval =
b.Left < p.Right &&
b.Right > p.Left &&
b.Top < p.Bottom &&
b.Bottom > p.Top;
}
// heading towards player two
else // m_ball.DX > 0
{
Rectangle b = m_ball.Rect;
Rectangle p = m_paddle2.Rect;
retval =
b.Left < p.Right &&
b.Right > p.Left &&
b.Top < p.Bottom &&
b.Bottom > p.Top;
}
return retval;
、、、
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/12445.html
標籤:其它游戲引擎
下一篇:Arduino小車
