使用此设置防止隧道传输?
我设置了一个简单的矩形瓷砖碰撞方案,并且效果很好。
唯一的问题是当你开始从壁架上掉下来时。你的速度达到了每帧 Y/X 变化足够大的程度,足以让你夹入固体物体并出现故障。
基本上我的设置如下:
首先,玩家的位置添加了速度,因此如果没有发生碰撞,玩家现在位于下一帧的位置。 下面的列表只是一个函数,checkIntersectTiles(Vector2 maskPos);
- 计算要检查的角色周围的图块。
- 循环遍历图块,包括边界图块内的图块。
- 检查玩家与每个图块的碰撞矩形。
- 如果存在交叉点,请将最大的违规轴移出图块,然后将该轴速度设置为 0。
- 继续检查。
当你夹入地面时,你会在里面抖动,因为我的算法试图将你移到与你碰撞最严重的瓷砖之外。
我的解决方案:检查从玩家的位置到玩家的位置+速度的每个位置。 我被困在这一点上。
有人可以帮我吗?
I have a simple rectangle-tile collision scheme set up, and it works beautifully.
The only problem is when you start falling off of a ledge. Your speed reaches the point where the change in Y/X each frame is large enough for you to clip into solid objects and glitch about.
Basically my setup is as follows:
To start with, the player's position has its velocity added to it, so the player is now at the place he would be next frame if no collisions happen.
The list below is just a single function, checkIntersectTiles(Vector2 maskPos);
- Calculate tiles around the character to check.
- Loop through tiles, including those inside the bounding tiles.
- Check the player's collision rectangle against each of these tiles.
- If there's an intersection, move the largest offending axis out of the tile, then set that axis velocity to 0.
- Continue checks.
When you clip into the ground, you jitter around inside, as my algorithm attempts to move you outside the tile that is most colliding with you.
My solution: Check each position from the player's pos, to the player's pos + velocity.
I'm stuck on that bit.
Can anyone give me a hand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您将玩家移出碰撞图块的代码只需一步即可完成。因此,如果玩家与图块发生碰撞,您确定 Y 方向的穿透深度为 5,您会立即将玩家 Y 位置调整 -5。
按照您的建议,检查每一步的玩家位置。因此,如果 Y 速度为 5,那么您可以将玩家的 Y 位置调整 1,检查碰撞,然后再重复 4 次。请参阅稍后处理时间步进的计算。下面只是一些基本的伪代码,并且只是在 Y 方向。
变成
如果您不调整流逝的时间,那就是简单的版本。如果是,那么您宁愿执行较小的时间步长
因此
,
在上面您将需要调整时间步长增量以确保平衡性能与准确性。您可能会考虑动态计算每帧的增量,以确保调整接近 1 个像素。
I assume that your code to move the player out of the colliding tile does so in a single step. So if the player collides with a tile you determine that the penetration depth is 5 in the Y direction you immediately adjust the player Y position by -5.
As you suggest, check the player position at each step. So if the Y velocity is 5 then you can adjust the players Y position by 1, check for collision and then repeat 4 more times. See later for calculations handling time stepping. The following is just some basic pseudo code and just in the Y direction.
Becomes
That is the simple version if you are not adjusting for ellaped time. If you are, then you rather perform smaller time steps
So
Becomes
In the above you will need to tune the time step delta to ensure that you balance performance with accuracy. You might event consider calculating the delta dynamically each frame to ensure that the adjustment is close to 1 pixel.