2
我已经写了一些代码,让任意大小的矩形与基于网格的地形设置(用于平台游戏)相冲突。我做的方式是这样的:修复地面碰撞代码中的“打嗝”?
For each tile the rectangle intersects with, do:
Calculate the primary axis that this tile is on with respect to the rectangle
Calculate the interpenetration of this tile into the rectangle along the primary axis (factoring in previous position offsets from other tiles)
If this tile is solid, add that interpenetration to a total collision resolution vector
Adjust the rectangle's position by the total calculated collision resolution vector
除非我碰到我的矩形被刚刚超过两个贴片的边界被拉入地随机“挂起起坐”这工作得很好,我的代码决定它需要通过在X轴上推动它来解决碰撞问题,从而停止矩形的运动,除非手动将其从地形中移出以克服它。
我试过一次只解决一个轴上的碰撞(所以如果Y轴分辨率最大,它会忽略任何x轴碰撞分辨率,反之亦然),但是当矩形正在被抖动时会导致抖动压在一个角落(因为这是一种情况,实际上需要同时解决两个轴)。
总之,我可以用什么方法一次解决这两个问题?