Collision with transition not working

Hi, i have this code:

onPlayerCollision = function(event) print("col") end ... player.collision = onPlayerCollision player:addEventListener( "collision", player ) ... tmp = display.newGroup() right = display.newRect(tmp, ... physics.addBody( right, { density=1.0, friction=1.0, bounce=1.0 } ) right.bodyType = "static" right:addEventListener( "collision", right ) ... transition.moveTo( tmp, { y=display.contentHeight+baseY\*20, time=4000 } )

Can somebody tell me why my collission event won’t work?

Is “player” a physical object? I don’t see that you’ve added a physics body to it, unless you just didn’t show that part of the code…

Also, you shouldn’t move or transition display groups independently of each other, if those groups contain physical objects and you need to detect collisions.

Best regards,

Brent

player = display.newRect(display.contentWidth/2, display.contentHeight/10\*9, 11\*baseX,11\*baseX) physics.addBody( player, {density=1.0, friction=1.0, bounce=1.0 } ) player.collision = onPlayerCollision player:addEventListener( "collision", player ) physics.setGravity(0, 0)

This is rest of player. So how do i have to move objects. There are “left” and “right” for each tmp group. Every tmp group is inserted to array.

Hello, Im lost on what you want exactly…

Maybe this?

tmp = display.newGroup() right = display.newRect(tmp, "box.png", 30, 30) physics.addBody( right, "static", { density=1.0, friction=1.0, bounce=1.0 } ) right:addEventListener( "collision", right ) onPlayerCollision = function(event) if event.phase == "began" then print("col") transition.moveTo( tmp, { y=display.contentHeight+baseY\*20, time=4000 } ) end end player = display.newRect(display.contentWidth/2, display.contentHeight/10\*9, 11\*baseX,11\*baseX) physics.addBody( player, {density=1.0, friction=1.0, bounce=1.0 } ) player.collision = onPlayerCollision player:addEventListener( "collision", player ) physics.setGravity(0, 0)

NOTE : i did not test the code… i just put it together…

Hi all,

Once again, for clarity and for all who may read this, you should not move/transition/scale entire display groups that contain physical objects unless you know the “rules” behind it all. Basically:

  1. You can move entire display groups which contain physical objects IF – and only if – you move/transition/scale all groups in unison.

  2. You can not put some physical objects into one group, other physical objects into a different group, and then move/transition/scale one group independently of the other (well technically you can, but collisions will not work as expected).

Basically the rule is this: for collisions to work within the structure of display groups, ALL groups must share the same coordinates and scale, which is of course x and y of 0,0 and scale of 100% by default. If you manipulate different groups independently, the physics engine will think that the group has not been manipulated, and collisions will occur as if that was the case.

Best regards,

Brent

Ok i see now what you wan’t to say :smiley: I’ve changed to move “left” and “right” on separate transitions and now it work.

Thanks for help :wink:

By the way. Docs are very poor. Many of very important thinks are not writen there.

The biggest problem is what i was supposing. That now left side starts to move a little bit earlier than right. 

Is “player” a physical object? I don’t see that you’ve added a physics body to it, unless you just didn’t show that part of the code…

Also, you shouldn’t move or transition display groups independently of each other, if those groups contain physical objects and you need to detect collisions.

Best regards,

Brent

player = display.newRect(display.contentWidth/2, display.contentHeight/10\*9, 11\*baseX,11\*baseX) physics.addBody( player, {density=1.0, friction=1.0, bounce=1.0 } ) player.collision = onPlayerCollision player:addEventListener( "collision", player ) physics.setGravity(0, 0)

This is rest of player. So how do i have to move objects. There are “left” and “right” for each tmp group. Every tmp group is inserted to array.

Hello, Im lost on what you want exactly…

Maybe this?

tmp = display.newGroup() right = display.newRect(tmp, "box.png", 30, 30) physics.addBody( right, "static", { density=1.0, friction=1.0, bounce=1.0 } ) right:addEventListener( "collision", right ) onPlayerCollision = function(event) if event.phase == "began" then print("col") transition.moveTo( tmp, { y=display.contentHeight+baseY\*20, time=4000 } ) end end player = display.newRect(display.contentWidth/2, display.contentHeight/10\*9, 11\*baseX,11\*baseX) physics.addBody( player, {density=1.0, friction=1.0, bounce=1.0 } ) player.collision = onPlayerCollision player:addEventListener( "collision", player ) physics.setGravity(0, 0)

NOTE : i did not test the code… i just put it together…

Hi all,

Once again, for clarity and for all who may read this, you should not move/transition/scale entire display groups that contain physical objects unless you know the “rules” behind it all. Basically:

  1. You can move entire display groups which contain physical objects IF – and only if – you move/transition/scale all groups in unison.

  2. You can not put some physical objects into one group, other physical objects into a different group, and then move/transition/scale one group independently of the other (well technically you can, but collisions will not work as expected).

Basically the rule is this: for collisions to work within the structure of display groups, ALL groups must share the same coordinates and scale, which is of course x and y of 0,0 and scale of 100% by default. If you manipulate different groups independently, the physics engine will think that the group has not been manipulated, and collisions will occur as if that was the case.

Best regards,

Brent

Ok i see now what you wan’t to say :smiley: I’ve changed to move “left” and “right” on separate transitions and now it work.

Thanks for help :wink:

By the way. Docs are very poor. Many of very important thinks are not writen there.

The biggest problem is what i was supposing. That now left side starts to move a little bit earlier than right.