Simple Physics: How to stop an object from moving?

Set-up: A game piece is moving as the result of a collision, and a small while later the piece must stop moving.

Question: How can this game piece be programmatically stopped from moving? Also, how would a game piece stop moving through a secondary collision with a different object?

Thank you!

-David

You could try this:

1
2
3
4
--Remove the physics when needed
physics.removeBody(object)
--Add the physics when needed
physics.addBody(object, "dynamic"] --(Or "static")

Hey, David, I'm not sure how your physics objects populate your screen and how they move, but I use the following to stop my physics objects:

1
2
myObject.angularVelocity = 0;
myObject:setLinearVelocity(0, 0);

What Naomi said above will stop the object from moving, but if you have any gravity at all it will be overwritten. The code above will only work if you have physics.setGravity(0, 0).

At least that is my understanding.

You guys are awesome!

I'm not using gravity, so I'll try setting the velocity to zero. Great idea!

Has anyone experimented with .isBodyActive set to false? Perhaps this might work too? I'll have to experiment.

Thank you!

-David

Hey, David, I haven't used isBodyActive property. If you do experiment with it, will you post back the result? I'd be so interested in learning how it might work.

Cheers,
Naomi

views:1330 update:2011/11/25 8:45:21
corona forums © 2003-2011