简体   繁体   English

LibGDX Box2d碰撞错误

[英]LibGDX Box2d Collision Error

I'm aware this is going to be somewhat vague. 我知道这会有些模糊。 I'm writing an action adventure style game and I'm having a random (as in seemingly spontaneous) issue where the body I'm using for the character is getting caught on nothing. 我正在编写动作冒险风格的游戏,但遇到一个随机的问题(看似自发的),我用来扮演角色的身体什么也没被抓住。 I'm not actually handling collisions, I'm just using the built in body touches body causes collision feature. 我实际上不是在处理碰撞,我只是在使用内置的身体接触物体引起碰撞功能。 The debug renderer indicates that there is a collision when there shouldn't be one and I can't discern why it would happen. 调试渲染器指示当不应该存在冲突时发生冲突,而我无法辨别为什么会发生冲突。 What I suppose I need is someone more familiar with LibGDX than I am to surmise why this would happen. 我想我需要的是对LibGDX更加熟悉的人,而不是我猜测为什么会发生这种情况。 玩家被困在左边

I guess @CoderMusgrove is right. 我猜@CoderMusgrove是正确的。
If you have a flat floor, created out of many boxes, you might get stuck on the edges of them. 如果您的地板平整,是由许多盒子组成的,则可能会卡在它们的边缘。
Thats because in the physics simulation, the body will be pushed down by gravity. 那是因为在物理模拟中,人体将因重力而被压低。 This results in a collision, which usualy pushes the body back up. 这会导致碰撞,通常会使身体后退。
But if you get pushed down in between two boxes, the collision resolver sometimes decides to push you back, as this is the shorter way out of the collision. 但是,如果您在两个方框之间被按下,则冲突解决程序有时会决定将您向后推,因为这是解决冲突的更短方法。
You can read more about this here . 您可以在此处了解更多信息。
Also the solutions are discussed in the link. 链接中还讨论了解决方案。 There are a few different ways: 有几种不同的方法:
- Cutting the edges: If you cut the edges of your character, the collision resolver will more likely decide to push your character up. -切割边缘:如果切割角色的边缘,则冲突解决程序将更有可能决定将角色向上推。 I tryed this solution to, but in my case it slowed down the character a bit. 我尝试使用此解决方案,但以我为例,它使字符稍微变慢了。 Also when i cut the edges to much, the character started jumping every time he moved onto another box. 同样,当我将边缘切得很多时,角色每次移动到另一个盒子时都会开始跳跃。
- Using edge-shapes: Instead of using boxes, you could just use edges. -使用边缘形状:您可以只使用边缘,而不必使用盒子。 It seems like you don't get stuck on edges that often, so that might allready solve your issue. 似乎您不会经常被困在边缘上,所以这可能已经解决了您的问题。
- Use gost vertices: Using Ghost Vertices, you can give the resolver a hint on how to resolve the colission. -使用gost顶点:使用Ghost顶点,可以为解析器提供有关如何解析大肠菌的提示。 Those ghost vertices are used for collision response only, so they won't affect the rest of the simmulation. 这些幻影顶点仅用于碰撞响应,因此它们不会影响其余的模拟。
- Combining boxes: The best solution would be to create one big box out of all adjacent boxes, if possible. -组合框:最好的解决方案是,如果可能的话,在所有相邻框中创建一个大框。 This would solve the problem, as there are no more edges where the body could get stuck. 这将解决问题,因为没有更多的边缘会卡住身体。

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

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