Physics Reset?

Hey guys,

I’m new to Corona (like… I’ve only been using it (and learning it) for 3 days) and I have to say I’m having fun. In fact, I’m having too much fun so I decided to create a simple game of myself.

I’ve been encountering a problem though with the physics engine. Cuz let’s say in my game, when an object hits something, it will cause notify the player that it’s game over, and when they click the reset button, the game resets (duh). So I’ve set up all my values to reset and all that, but one thing I’ve noticed is that the physics properties (or whatever you call it) that it had right when I paused the physics engine will be exactly like how it is when I start it up again after all the values reset. So let’s say, since that object hit something - game over, and the game resets, I’ve made it so that the object returns to a place far from where it will hit something for it to end the game before I resume the physics engine, and yet, at the first frame it detects it at once that there was a collision (even if clearly it is seen that the two objects are far apart). Weird.

And if it helps, I don’t stop the physics engine, I pause it.

Sorry if my explanation’s kinda fuzzy. I’m kinda tired (and sleepy) right now. [import]uid: 45459 topic_id: 8008 reply_id: 308008[/import]

And why won’t you stop the physic and start it again? [import]uid: 42078 topic_id: 8008 reply_id: 28509[/import]

I’m having a very similar problem: if you apply a transition on a physics object changing its size, the physics engine will still use the original size values from before the transition to calculate the physics (e.g. the physics box doesn’t match the shape anymore)

doing a simple physics.stop() and physics.start() doesn’t seem to work

for example:

local test = display.newRect(center.x, center.y, 100, 100)  
  
function restartPhysics()  
 physics.stop()  
 physics.start()  
end  
  
physics.addBody(test, 'dynamic')  
transition.to(test, {time=5000, width=20, onComplete=restartPhysics})  

does not have the desired effect [import]uid: 44968 topic_id: 8008 reply_id: 28549[/import]

the physics.stop/start function can’t change the body size. instead of having a function that stops and starts the physics, hvae a function that destroys / creates a new object with the desired size [import]uid: 14018 topic_id: 8008 reply_id: 28561[/import]

thats what i suspected, thanks for the reply :slight_smile:
its quite difficult to make it look good though, since the object i’m replacing has several joints with other objects (like a puppet) and can be at any direction or rotation, but the new object doesn’t have the same kind of momentum when spawned [import]uid: 44968 topic_id: 8008 reply_id: 28582[/import]

@nahir

thanks for the tip! seems to work so far. :slight_smile: [import]uid: 45459 topic_id: 8008 reply_id: 28586[/import]