开发者

How to detect collision to shape like tree?

I'm making IPhone game using cocos2d, I already know how to detect collision using rect. and also I know there is many questions and answer similar with mine. but I didn't find answer which fit my situation.

I'm shooting arrow to tree. as you know tree is not like a rect at all. th开发者_高级运维en how to detect collision to tree? Should I fill my tree with many rect? It doesn't seem good solution. Is there any other choice?

Thanks guys.


You should check this brilliant tutorial: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone by Ryan Wenderlich. It's easy to follow, comes with source code and addresses the problem of collision detection on irregular shapes.


Usually you try to create a bounding box that is as close to the form of the tree as possible. In this example you could use a circle for the crown of the tree and a rect for the stem. However if you do not have too many trees you can also use something more complex. Just try out on the device whether you take any performance hits.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜