Rahul Singh
Rahul Singh

Reputation: 1229

collision detection in corona

i am trying to move one of my physics body to a different xAxis on collision

local function onCollision(self,event)
            if event.other.name == "block" then
                if  (event.other.x - self.x) > 210 then
                    self:removeSelf()
                    self = nil
                    transition.cancel( event.other.move )
                    event.other:removeSelf()
                    event.other = nil
                    gameOver()
                else
                    print("else")
                    transition.cancel( event.other.move )
                    event.other.x = 1024
                    updateScore(1)
                end
            end
        end
        ball.collision = onCollision
        ball("collision",ball)

but it is saying

"Cannot translate an object before collision is resolved"

How can I do that ?

Upvotes: 0

Views: 1463

Answers (2)

Mahesh Jayachandran
Mahesh Jayachandran

Reputation: 129

transition.to(ball, {x = object.x, y= object.x, time=0})

I found the answer to the question.

Upvotes: 0

SatheeshJM
SatheeshJM

Reputation: 3633

You have to give a frame delay if you want to move colliding objects.

Replace

 event.other.x = 1024 

with

local translateObject = function()  event.other.x = 1024 end
timer.performWithDelay(1,translateObject,1)

Upvotes: 1

Related Questions