Little help with collisions

Hey Guys.

Im having a bit of trouble with collisions. I coded a method that detects collisions just fine using physics. The problem is that one of the actors instead of moving towards the object I want it to collide it does a transition.to and makes itself bigger.

The problem is that the collision detection doesn’t work with the actor that had its height modified. It only colides with the original size actor.

I made a quick demo (ipad size) for you to see what i am talking about here is the code:

If you press the red square the yellow one will start to grow and eventually hit the whitebox. The problem im having is that if I place the white hitbox on top of the yellow one by changing its x position to 600 you will see in the terminal the output message that the objects are colliding.

But if leave the white box on top of the yellowbox you wont get the output message that the objects are colliding after the yellowbox grows and collides with the white one.

Thank you for your help

local physics = require (“physics”)
physics.start()
physics.setGravity(0,0)
local lengua = display.newRect( 0, 0, 20, 100 )
physics.addBody( lengua, {isSensor = true} )
lengua.name = “lengua”
lengua:setFillColor( 255, 255, 0 )
lengua.x = 500
lengua.y = 600
local hitbox = display.newRect( 0, 0, 100, 100 )
physics.addBody( hitbox, {isSensor = true} )
hitbox.name = “hitbox”
hitbox.x = 500
hitbox.y = 400

local button = display.newRect( 0, 0, 100, 100 )
button:setFillColor( 255, 0, 0 )
button.x = 100
button.y = 600

local function retract ()

transition.to(lengua, {time=300, delay = 200, height = 50 } )
– transition.to(lengua, {time=300, x = 600 } )

end

local onTouch = nil
onTouch = function (_e)
if _e.phase == ‘began’ then

transition.to(lengua, {time=300, delay = 200, height = 350, onComplete=retract } )

end

end

button:addEventListener(“touch”, onTouch )
local function onCollisionLengua(self,event)
if event.phase == “began” then
if event.other.name == “hitbox” then

print(event.name… " colliding with: "… event.other.name)

end
end
end

lengua.collision = onCollisionLengua
lengua:addEventListener(“collision”, lengua)
[import]uid: 111657 topic_id: 20277 reply_id: 320277[/import]

Last two lines should usually just be one like

Lengua:addEventListener("collision", onCollisionLengua )  

At least this usually works for me [import]uid: 31078 topic_id: 20277 reply_id: 79271[/import]

Hello there

I tried replacing the two lines on my code with yours and whenever there is a collision (when I places the hitbox on top of the yellowbox) I get an error and it doesn’t detect the collision And still doesnt detect the yellowbox when I make it bigger with the transition to function.

I know the collision method works because I used it before with no problem. But I dont know why its not detecting objects that get bigger and collide

Any other Ideas?

thank you very much [import]uid: 111657 topic_id: 20277 reply_id: 79292[/import]

any ideas guys? [import]uid: 111657 topic_id: 20277 reply_id: 79437[/import]