将多个碰撞形状附加到单个刚体
我使用 iOS + Cocos2d + Chipmunk 创建了一个单人游戏,我正在寻找一个解决方案来演示如何将多个碰撞形状附加到单个刚体。我有一个形状不规则的目标(汽车),我需要检测其碰撞。玩家从侧视图看到目标(汽车),其他物体可能会从多个方向撞击目标,而不仅仅是从前面或后面。由于形状如此,我无法使用单个 cpPolyShape 来实现逼真的碰撞效果。两个 cpPolyShapes(矩形)堆叠在一起,底部矩形较大应该可以解决问题。
有人可以举个例子来说明如何实现这一点吗?
我阅读了有关 cpShape 的 Chipmunk 文档,http://code.google.com/p /chipmunk-physicals/wiki/cpShape,它在注释部分的页面最底部指出“您可以将多个碰撞形状附加到刚体”,但没有提供示例。
我目前有一个正在运行的功能性项目,并正在尝试进行一些最终调整以改进游戏玩法。
I have created a single player game using iOS + Cocos2d + Chipmunk and I'm looking for a solution that demonstrates how to attach multiple collision shapes to a single rigid body. I have a target that has an irregular shape (a car) that I need to detect collisions for. The target (car) is seen by the player from a side view and other objects may impact the target from multiple directions, not just from the front or the rear. The shape is such that I am unable to use a single cpPolyShape and achieve a realistic collision effect. Two cpPolyShapes (rectangular) stacked on top of each other, with the bottom rectangle being larger should do the trick.
Can someone provide a example of how this can be achieved?
I read the Chipmunk docs about cpShape, http://code.google.com/p/chipmunk-physics/wiki/cpShape, and it states that 'You can attach multiple collision shapes to a rigid body' in the very bottom of the page in the notes section, but no example is provided.
I currently have a working, functional project and am trying to make some final adjustments to improve game play.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您调用 cp*ShapeNew() 时,第一个参数是要将其附加到的主体。简单地制作多个共享同一主体的形状。没有什么窍门。
When you call cp*ShapeNew(), the first parameter is the body to attach it to. Simple make more than one shape that share the same body. There is no trick.
您可以添加方法
在 .h 文件中添加原型
现在在 .m 文件中添加代码:
注意:- 不要忘记给出两个 Body 的碰撞类型。
You can add the method
In the .h file add the prototype
Now in the .m file add the code as
Note:- Don't Forget to give the collision type of both Body.