Collisions and Transitions

I’ve been working on a problem for a while now and I just cannot figure it out.

Object 1 moves with a transition, and when it collides with a different object, it cancels the transition temporarily, pauses for a second to make the other object nil, and then starts its transition again.

This is the basic set up I am using to do this:

function collide(self, event)  
 if (event.phase == "began") then  
 transition.cancel(self.myTransition)  
 nilEventOther()  
 return true  
  
 elseif (event.phase =="ended") then  
 self.myTransition = transition.to(self, {time=1000, x=self.x + 90, onComplete=moveAgain})  
 print("stopped colliding")  
 return true  
 end  
end  

This works fine when Object 1 only collides with one other object at a time. When it collides with two objects at a time, though, it will nil the one object, but then it will just start the transition again after that object is gone, and completely ignore the second object.

What can I do to make it so Object 1 recognizes the second object and will not continue moving until all objects it collides with are gone? [import]uid: 45667 topic_id: 22122 reply_id: 322122[/import]

Add a counter and do +1 when the event.phase is began for collision, -1 when it ends. Only do the second transition if the counter = 0.

:slight_smile: [import]uid: 52491 topic_id: 22122 reply_id: 88021[/import]

Awesome. That worked.

I tried to do the -1 to collision counter in the nilEvent() function, but it didn’t quite solve the problem. Looks like i was putting it in the wrong spot.

Thanks again for helping me out! [import]uid: 45667 topic_id: 22122 reply_id: 88038[/import]

Not a problem, thank you for the appreciation!

Good luck with your project :slight_smile: [import]uid: 52491 topic_id: 22122 reply_id: 88054[/import]