I was wondering if there is any way to stop a collision from producing a force on a dynamic object.
For instance, if a moving ship collides with a still ship, the still ship will not move when hit.
I was wondering if there is any way to stop a collision from producing a force on a dynamic object.
For instance, if a moving ship collides with a still ship, the still ship will not move when hit.
No. Make the object you want to NOT move a “kinematic” body type.
Note. If you can’t use a kinematic body, you might try this:
At time of collision, do this to the object that was hit and must not move:
obj:setLinearVelocity(0,0) obj.angularVelocity = 0
Then set a timer to re-stop the object response
timer.performWidthDelay( 1, function() obj:setLinearVelocity(0,0) obj.angularVelocity = 0 end )
This may not work consistently however. i.e. There may still be motion/response.
Additionally, this will interfere with any other code you may have that is moving that object.
Another way to ‘minimize’ collision responses is to:
Make the hitting object have a very low mass (via the density value):
physics.addBody( bullet, { density = 0.01 …
Make the collidee (the object that is hit and you don’t want to move) have very high mass (via the density value):
physics.addBody( ship, { density = 1e6, …
Thank you, I will implement these and see how they go.
H sdktester15,
try set .isBodyActive to false for object using timer with 1ms delay :
timer.performWidthDelay( 1, function() ship.isBodyActive = false end )
From Corona documentation
Gotchas
If this property is set to false on an active object currently in collision state with another, a collision with a phase of “ended” will immediately be triggered. Likewise, if this property is set to true on an inactive object currently in collision state with another, a collision with a phase of “began” will immediately be triggered.
Have a nice day:)
ldurniat
Thanks, I’ve discovered a bit of a workaround for this in my case.
But, this is good to know in case I need it later.
No. Make the object you want to NOT move a “kinematic” body type.
Note. If you can’t use a kinematic body, you might try this:
At time of collision, do this to the object that was hit and must not move:
obj:setLinearVelocity(0,0) obj.angularVelocity = 0
Then set a timer to re-stop the object response
timer.performWidthDelay( 1, function() obj:setLinearVelocity(0,0) obj.angularVelocity = 0 end )
This may not work consistently however. i.e. There may still be motion/response.
Additionally, this will interfere with any other code you may have that is moving that object.
Another way to ‘minimize’ collision responses is to:
Make the hitting object have a very low mass (via the density value):
physics.addBody( bullet, { density = 0.01 …
Make the collidee (the object that is hit and you don’t want to move) have very high mass (via the density value):
physics.addBody( ship, { density = 1e6, …
Thank you, I will implement these and see how they go.
H sdktester15,
try set .isBodyActive to false for object using timer with 1ms delay :
timer.performWidthDelay( 1, function() ship.isBodyActive = false end )
From Corona documentation
Gotchas
If this property is set to false on an active object currently in collision state with another, a collision with a phase of “ended” will immediately be triggered. Likewise, if this property is set to true on an inactive object currently in collision state with another, a collision with a phase of “began” will immediately be triggered.
Have a nice day:)
ldurniat
Thanks, I’ve discovered a bit of a workaround for this in my case.
But, this is good to know in case I need it later.