简体   繁体   English

Box2d:动态物体未完全与运动物体接触

[英]Box2d: dynamic body does not contact with kinematic body completely

I'm building a simple platformer game based on box2d. 我正在基于box2d构建一个简单的平台游戏。

Player is made as ChainShape dynamic polygon object with two sensors (bottom and top). 将播放器制成为具有两个传感器(底部和顶部)的ChainShape动态多边形对象。

Floor object is a simple kinematic box. 地板对象是一个简单的运动盒。

Problem is that for some reason, player body never fully fall down on the floor body - there is always several pixels between them, making player sprite to look like it is flying above the floor and not standing on it. 问题在于,由于某种原因,玩家身体永远不会完全掉落在地板主体上-它们之间总是有几个像素,这使得玩家精灵看起来像是在地板上方飞行而不站在地面上。

Here is a couple of enlarged screenshots: 1) player jumping (body looks fine): 以下是几个放大的屏幕截图:1)玩家跳跃(身体看起来不错): 球员跳(身体看起来不错)

2) player is standing on the floor (something appears at the bottom of player's body and prevents it from contacting with the floor): 2)玩家站在地板上(某些东西出现在玩家身体的底部,并防止其与地板接触): 在此处输入图片说明

Kinematic bodies contact with the floor correctly. 运动机构正确接触地板。

What can be the problem? 可能是什么问题?

I found an answer here http://www.iforce2d.net/b2dtut/gotchas#smallgap 我在这里找到了答案http://www.iforce2d.net/b2dtut/gotchas#smallgap

I had 250pixels per box2d unit, so 0.005 of that equals 1.25pixels. 我每个box2d单位有250个像素,所以其中的0.005等于1.25个像素。 Additionally to that it seems that this linearSlope comes from both fixtures, eventually resulting in 2-3 pixel gap. 除此之外,该linearSlope似乎来自两个固定装置,最终导致2-3个像素的间隙。

After changing the world (I had to make 250 pixels to be 5 units, increase gravity 5 times and increase all horizontal velocities also 5 times to get the same game feeling as it was) problem seems to be resolved. 改变世界后(我必须将250像素设置为5个单位,将引力增加5倍,并将所有水平速度也增加5倍才能获得与原来相同的游戏感觉),问题似乎已经解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM