avoiding collision in corona sdk

房东的猫 提交于 2019-12-07 19:21:28

问题


How to avoid collision between physics bodies in corona ? The application that I am developing makes use of many physics bodies.I want collision to happen between two desired bodies,but the collision is happening between all the bodies in the system.Can anyone help me with a solution?


回答1:


There is the second method to assign a groupIndex to each object. The value can be a positive or negative integer, and is a simpler way of specifying collision rules: objects with the same positive groupIndex value will always collide with each other, and objects with the same negative groupIndex value will never collide with each other.

local collisionFilter = { groupIndex = 2 }
physics.addBody(object1, {bounce = .2, density = 1, filter = collisionFilter})
physics.addBody(object2, {bounce = .2, density = 1, filter = collisionFilter})



回答2:


You need to create a 'collision filter' adding both 'categoryBits' and 'maskBits' to every object. You assign a number to both them in physics body. Something like:

physics.addBody(object, {bounce = .2, density = 1, filter = {maskBits = 2, categoryBits = 4}})

Mask bits will only collide with an objects with same category bit. So an object with maskBit = 2 will only collide with an object with a categoryBit = 2.

You can assign any number you want as far a I know.




回答3:


The concept is Collision Filtering. This link might help.

http://developer.anscamobile.com/forum/2010/10/25/collision-filters-helper-chart




回答4:


The numbers need to be in powers of 2. Not any number.




回答5:


I know this has already been answered but this might be useful for you. I used object.isSensor = true on my project so that even if the object has a physics body, it won't collide with other objects.



来源:https://stackoverflow.com/questions/8200505/avoiding-collision-in-corona-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!