简体   繁体   English

Box2D AS3-刷新形状还是Hitbox?

[英]Box2D AS3 - Refreshing the Shape or Hitbox?

I'm currently trying to implement a "crouch" function in my game. 我目前正在尝试在游戏中实现“蹲下”功能。 I'm using WCK with Box2D. 我在Box2D中使用WCK。

I have something rather basic, I generate my main character as an extension of a shape. 我有一些基本的东西,我将主角生成为形状的扩展。 This means that collision is automatically generated from the getgo. 这意味着碰撞是从getgo自动生成的。 This is wonderful for a lot of things, but not everything. 对于很多事情来说,这是很棒的,但并非一切。

I have a crouch/roll function. 我有蹲伏/滚动功能。 The problem is that the hitbox for crouching and standing are the same, so if a box drops onto you while crouching it "levitates" ontop of you since the hitbox is still the standing hitbox. 问题在于,卧卧和站立的击打箱是相同的,因此,如果卧箱在蹲下时掉落到您身上,它会“悬浮”在您的顶部,因为击打箱仍然是站立的击打箱。

How would I go about "refreshing" the shape collision? 我将如何“刷新”形状碰撞? Is there a way to delete the collision and make Box2D recalculate? 有没有办法删除碰撞并使Box2D重新计算?

It's possible to filter contacts and prevent them from happening (using a contact listener or iterating the world's contact list) but I think there are better ways to do what you want. 可以过滤联系人并阻止它们发生(使用联系人侦听器或遍历世界的联系人列表),但是我认为有更好的方法来完成您想要的事情。

You could split the body in two parts, and connect them with a prismatic joint (limits and motor enabled, collideConnected disabled). 您可以将车体分为两部分,然后用棱柱形接头连接(启用了限制和马达,禁用了collideConnected)。 Standing up you'd have the motor push the parts apart to the upper limit and when crouching you'd pull them together to the lower limit thus reducing the height. 站立时,电机将零件推开至上限,蹲伏时将其拉至下限,从而减小了高度。

If you need really different shapes (eg a rectangle when standing and a circle for rolling around metroid style) this might work: Add both shape's fixtures to the body and use mask filtering to prevent the one you don't need from colliding with anything. 如果您确实需要不同的形状(例如,站立时为矩形,而在摆线样式中为圆形),则可以使用:将两个形状的灯具都添加到身体上,并使用遮罩过滤来防止不需要的形状与任何物体碰撞。

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

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