实际上彼此靠近的Box2d实体在“卡住"状态. [英] Box2d Bodies that are really close together, are getting "stuck"

查看:129
本文介绍了实际上彼此靠近的Box2d实体在“卡住"状态.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用平铺的tmx贴图,我创建了一个将实体添加到特定层中每个平铺块的类.到目前为止,这种方法一直很有效,除了当角色或敌人在屏幕上四处移动时,其身体卡在两个图块之间的边缘上.

Im using a tiled tmx map, and I created a class that adds bodies to each tile within a certain layer. This has been working great so far except for when a character or an enemy moves around on the screen, its body gets stuck on an edge between two tiles.

这似乎有时"发生在某些地方.跳跃会使您放松,但发生时会令人烦恼,我尝试增加位置迭代次数,但问题不断发生.

This seems to happen "sometimes" and in certain spots. Jumping makes u unstuck but its annoying when it happens, and i tried increasing the position iterations, but the problem keeps reoccurring.

以下是我的游戏外观: http://i.stack.imgur.com/f5Igm .png 我没有渲染图块,以便更轻松地查看图块的主体是什么

Heres what my game looks like: http://i.stack.imgur.com/f5Igm.png I didnt render the tiles so that its easier to see what the tile's body looks like

推荐答案

发生的事情是,上部动态物体的皮肤"可以嵌入其下方的形状中.然后,如果上半身在下半身的形状上移动并遇到其中一个形状的一个角,则物理引擎会产生与行进方向相反的冲动.

What happens is that an upper dynamic body's "skin" can get embedded into the shapes below it. If the upper body is then moved across the lower shapes and encounters a corner of one of those shapes, then an impulse is generated by the physics engine that's in opposition to the direction of travel.

景气!上身卡住了.

下面是放大的图像,显​​示了向右移动的上部矩形:

Here's a zoomed in image showing this for an upper rectangle moving to the right:

从其延伸的蓝色点和线是Box2D歧管计算代码确定需要施加脉冲的地方.请注意红色/棕色矩形右侧的蓝色点和线.这些是相反的冲动.

The blue dots and lines extending from them are where the Box2D manifold calculation code has determined impulses need to be applied. Note the blue dots and lines that are on the right side of the reddish/brown rectangle. Those are opposing impulses.

一个解决方案(如三十二上校"在评论中建议的那样)是在边缘形状的较低形状中使用重影顶点"机制(或仅使用可为您有效计算边缘的链形形状).

A solution, as Colonel Thirty Two suggested in the comments, is to use the "ghost-vertices" mechanism in edge shapes for the lower shapes (or just use a chain shape that effectively calculates the edges for you).

作为背景,我有自己的 Box2D叉我只是针对这个问题推出了另一种解决方案,该解决方案不需要将较低的形状变成边缘(或链形)形状.我还完成了有关此替代方法的文章.

As background, I have my own fork of Box2D that I've been developing and I just pushed out an alternative solution for this very problem that doesn't require the lower shapes to be edge (or chain) shapes. I've also done a write-up of this alternative.

这篇关于实际上彼此靠近的Box2d实体在“卡住"状态.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆