pushing bodies

Hi All

anyone know a way of stoping 2 dynamic bodies pushing each other? i have set the LinearVelocity on both objects so they move to each other but don’t want them to be able to push each other arround. oh and i have also set the fixed rotation:

when ether object moves towards the other while colliding pushing occurs…

physics.addBody(object1,“dynamic”,{density = 0, friction = 0, bounce = 0});
object1.isFixedRotation = true

physics.addBody(object2,“dynamic”,{density = 0, friction = 0, bounce = 0});
object2.isFixedRotation = true

object1:setLinearVelocity(ob1dirx*20, ob1diry*20)

object2:setLinearVelocity(ob2dirx*20, ob2diry*20)

Thx

Sparrow

Hi @Sparrow,

There are three options for this, depending on your needs:

  1. Make one (or both) bodies into a sensor object.

  2. Use collision filters to prevent those particular bodies from interacting with each other.

  3. Use pre-collision and physics contact to “void” the collision before it occurs.

If you’re not familiar with any of these, I can explain further depending on which one you think sounds correct.

Best regards,

Brent

Thx Brent

i would like to keep both as dynamic as i have static objects as walls. please could you explain the pre-collision and physics contact to “void” the collision before it occurs on 2 moving dynamic objects?

i assume i can add this to my moveobject1/moveobject2 functions, thx for your help.

thx

Sparrow

I’m not sure if this is what you meant, but if you want the objects just to pass through each other you could use collision filter with same negative groupIndex to avoid collisions between those objects. A small example where circle bodies collide only with the static floor:

[lua]

local physics = require(“physics”)

local circle1 = display.newCircle(display.contentCenterX,display.contentCenterY,10)
local circle2 = display.newCircle(display.contentCenterX,display.contentCenterY-30,10)
local rect1 = display.newRect(0,display.contentHeight-20,display.contentWidth,20)
rect1.anchorX = 0
rect1.anchorY = 0
physics:start()
physics.addBody(rect1,“static”)
physics.addBody(circle1,“dynamic”, {filter = {groupIndex=-1}})
physics.addBody(circle2,“dynamic”, {filter = {groupIndex=-1}})

[/lua]

Hi Sparrow,

To confirm what @Sape says, you can use collision filters to prevent those objects from ever colliding with each other (however they would continue to collide with the walls). Here’s a handy chart I created some time back which can help you calculate the values:

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

If you were to need really advanced behavior, like per-object collision “voiding” in certain cases, then you’d need to rely on the physics contact method. But I don’t sense that you need this kind of behavior.

Take care,

Brent

Awesome stuff guys! thx to the both of you for your help,

I have implemented these and they work great.

Hi @Sparrow,

There are three options for this, depending on your needs:

  1. Make one (or both) bodies into a sensor object.

  2. Use collision filters to prevent those particular bodies from interacting with each other.

  3. Use pre-collision and physics contact to “void” the collision before it occurs.

If you’re not familiar with any of these, I can explain further depending on which one you think sounds correct.

Best regards,

Brent

Thx Brent

i would like to keep both as dynamic as i have static objects as walls. please could you explain the pre-collision and physics contact to “void” the collision before it occurs on 2 moving dynamic objects?

i assume i can add this to my moveobject1/moveobject2 functions, thx for your help.

thx

Sparrow

I’m not sure if this is what you meant, but if you want the objects just to pass through each other you could use collision filter with same negative groupIndex to avoid collisions between those objects. A small example where circle bodies collide only with the static floor:

[lua]

local physics = require(“physics”)

local circle1 = display.newCircle(display.contentCenterX,display.contentCenterY,10)
local circle2 = display.newCircle(display.contentCenterX,display.contentCenterY-30,10)
local rect1 = display.newRect(0,display.contentHeight-20,display.contentWidth,20)
rect1.anchorX = 0
rect1.anchorY = 0
physics:start()
physics.addBody(rect1,“static”)
physics.addBody(circle1,“dynamic”, {filter = {groupIndex=-1}})
physics.addBody(circle2,“dynamic”, {filter = {groupIndex=-1}})

[/lua]

Hi Sparrow,

To confirm what @Sape says, you can use collision filters to prevent those objects from ever colliding with each other (however they would continue to collide with the walls). Here’s a handy chart I created some time back which can help you calculate the values:

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

If you were to need really advanced behavior, like per-object collision “voiding” in certain cases, then you’d need to rely on the physics contact method. But I don’t sense that you need this kind of behavior.

Take care,

Brent

Awesome stuff guys! thx to the both of you for your help,

I have implemented these and they work great.