transition.to physics problem

Hey guys,

I’m making puzzle game and I have problem with transition.to.

It works fine, I mean it does what it should do but not really. It moves player to start position

every time user press restart button but after few retries(pressing restart button) player press GO button and physics start and they are applied to player pretty strange, like I applied force to player which I don’t.

It acts like sprite which was on starting position pushes down existing sprite when it moves to start position.

Here’s my code for restart button. 

Hope anyone can help.

local btnrepPress = function( event ) transition.to(billy, {x = 200 , y = 100, time=0, rotation = 0}) physics.pause() rotate:addEventListener("touch", rotateObj) circle:addEventListener("touch", onTouch) circle:addEventListener("touch") end

EDIT : I actually found the problem. It’s not problem with transition.to or anything like that.The problem is that physics are just paused with rep button which means they will continue doing what they wanted when I start them again so if object was falling and I pause physics and change x and y of object when I start physics again object will sort of double fall. Is there any way to reset physics? I’ve tried physics.stop() but once u call it there is no way to start physics again at least I couldn’t manage to do so.

Can you show your code for the GO button press?   

Why not just set billy.x and billy.y directly instead of a transition that takes 0 ms?

GO button basiclly starts physics ( physics.start() ) and removes listeners for few objects.

I would just set x and y but I cant because of collision that’s happening when billy collides with laser.

Please anyone I still didn’t solve this. Is there any alternative to transition.to?

Huh I managed how to solve this. If anyone runs in this kind of trouble remove the object from physics physics.removeBody(object) and then put object back to physics when u need it. Here how my code looks like now

function physicsCleaner( event ) physics.removeBody(billy) star1.isVisible = true star2.isVisible = true star3.isVisible = true end local goPress = function( event ) physics.addBody(billy,"dynamic",{density=1, bounce=0.5, friction=1.0, radius=27}) physics.start() circle:removeEventListener( "touch", circle ) rotate:removeEventListener("touch", rotateObj) circle:removeEventListener("touch", onTouch) rotator:removeEventListener("touch", rotatorObj) line1:removeEventListener("touch", onTouch) line1:removeEventListener("touch") line2:removeEventListener( "touch", line2 ) krotator:removeEventListener("touch", krotatorObj) line2:removeEventListener("touch", onTouchK) line3:removeEventListener( "touch", line3 ) l3krotator:removeEventListener("touch", l3krotatorObj) line3:removeEventListener("touch", onTouchl3) line4:removeEventListener( "touch", line4 ) l4krotator:removeEventListener("touch", l4krotatorObj) line4:removeEventListener("touch", onTouchl4) end local btnrepPress = function( event ) timer.performWithDelay( 1, physicsCleaner ) physics.pause() transition.to(billy, {x = 50 , y= 70, time=0, rotation = 0}) circle:addEventListener( "touch", circle ) rotate:addEventListener("touch", rotateObj) circle:addEventListener("touch", onTouch) rotator:addEventListener("touch", rotatorObj) line1:addEventListener("touch", onTouch) line1:addEventListener("touch") line2:addEventListener( "touch", line2 ) krotator:addEventListener("touch", krotatorObj) line2:addEventListener("touch", onTouchK) line3:addEventListener( "touch", line3 ) l3krotator:addEventListener("touch", l3krotatorObj) line3:addEventListener("touch", onTouchl3) line4:addEventListener( "touch", line4 ) l4krotator:addEventListener("touch", l4krotatorObj) line4:addEventListener("touch", onTouchl4) end

You don’t need to remove the body, just change it’s type to kinematic during the transition.  This is what you are supposed to do when moving objects outside of the physics simulation.  Then set it back to “dynamic” when you want physics to resume moving the item. 

Rob

Nope, I have tried this but it’s not working at least on object that has it’s listener. I will use this with removing as I didn’t noticed any problem.

Can you show your code for the GO button press?   

Why not just set billy.x and billy.y directly instead of a transition that takes 0 ms?

GO button basiclly starts physics ( physics.start() ) and removes listeners for few objects.

I would just set x and y but I cant because of collision that’s happening when billy collides with laser.

Please anyone I still didn’t solve this. Is there any alternative to transition.to?

Huh I managed how to solve this. If anyone runs in this kind of trouble remove the object from physics physics.removeBody(object) and then put object back to physics when u need it. Here how my code looks like now

function physicsCleaner( event ) physics.removeBody(billy) star1.isVisible = true star2.isVisible = true star3.isVisible = true end local goPress = function( event ) physics.addBody(billy,"dynamic",{density=1, bounce=0.5, friction=1.0, radius=27}) physics.start() circle:removeEventListener( "touch", circle ) rotate:removeEventListener("touch", rotateObj) circle:removeEventListener("touch", onTouch) rotator:removeEventListener("touch", rotatorObj) line1:removeEventListener("touch", onTouch) line1:removeEventListener("touch") line2:removeEventListener( "touch", line2 ) krotator:removeEventListener("touch", krotatorObj) line2:removeEventListener("touch", onTouchK) line3:removeEventListener( "touch", line3 ) l3krotator:removeEventListener("touch", l3krotatorObj) line3:removeEventListener("touch", onTouchl3) line4:removeEventListener( "touch", line4 ) l4krotator:removeEventListener("touch", l4krotatorObj) line4:removeEventListener("touch", onTouchl4) end local btnrepPress = function( event ) timer.performWithDelay( 1, physicsCleaner ) physics.pause() transition.to(billy, {x = 50 , y= 70, time=0, rotation = 0}) circle:addEventListener( "touch", circle ) rotate:addEventListener("touch", rotateObj) circle:addEventListener("touch", onTouch) rotator:addEventListener("touch", rotatorObj) line1:addEventListener("touch", onTouch) line1:addEventListener("touch") line2:addEventListener( "touch", line2 ) krotator:addEventListener("touch", krotatorObj) line2:addEventListener("touch", onTouchK) line3:addEventListener( "touch", line3 ) l3krotator:addEventListener("touch", l3krotatorObj) line3:addEventListener("touch", onTouchl3) line4:addEventListener( "touch", line4 ) l4krotator:addEventListener("touch", l4krotatorObj) line4:addEventListener("touch", onTouchl4) end

You don’t need to remove the body, just change it’s type to kinematic during the transition.  This is what you are supposed to do when moving objects outside of the physics simulation.  Then set it back to “dynamic” when you want physics to resume moving the item. 

Rob

Nope, I have tried this but it’s not working at least on object that has it’s listener. I will use this with removing as I didn’t noticed any problem.