Grid “固定”;“打嗝”;地面碰撞代码?

Grid “固定”;“打嗝”;地面碰撞代码?,grid,2d,collision-detection,Grid,2d,Collision Detection,我已经编写了一些代码,可以让任意大小的矩形与基于网格的地形设置发生碰撞(用于platformer游戏)。我是这样做的: 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 re

我已经编写了一些代码,可以让任意大小的矩形与基于网格的地形设置发生碰撞(用于platformer游戏)。我是这样做的:

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轴碰撞分辨率,反之亦然),但当矩形被压入角点时,会导致抖动(因为这是一种实际需要同时解决两个轴的情况)


简而言之,我可以用什么方法一次解决这两个问题?

这是一个非常困难的问题,因为在某些情况下,它有无穷多的交互作用

要在速度和精度之间进行选择:

1.为每个对象(矩形)添加交互计数器

  • 碰撞检测前,将所有计数器重置为零
2.如果检测到任何碰撞,则为碰撞中的所有对象增加计数器

3.如果计数器值超过极限值,停止计算该对象的相互作用


请注意,这种方法也可能会在被迫的情况下造成一些打嗝,但不会挂断。

这是一个非常困难的问题,因为在某些情况下,它有无穷多的交互作用

要在速度和精度之间进行选择:

1.为每个对象(矩形)添加交互计数器

  • 碰撞检测前,将所有计数器重置为零
2.如果检测到任何碰撞,则为碰撞中的所有对象增加计数器

3.如果计数器值超过极限值,停止计算该对象的相互作用

请注意,如果被迫这样做,这种方法也会造成一些小问题,但不会挂断