Stop physics on collision with specific object.

Hi all.

I spawn some objects which I want to be able to bounce of some objecttypes and “die” on collision with other objecttypes.

I use object.type = “killme” to detect if the object should die on collision or not.

It Works ok except for the fact that the animations etc. that I run on a “kill” seems to take so long time that the physics keep going … 

I can almost avoid this by setting linear velocity to zero, but if i have a lot of bounce the object will actually manage to bounce a Little bit before the collision is “fully detected” and velocity set to zero.

So question is … How do I manage to disable the bouncing if the object should die?

/C

Hi @cwe,

If you set the linear velocity to 0 on collision, the body should stop immediately. Are there other objects that are colliding with the “dead” object and making it bounce a bit as the animation completes?

Regards,

Brent

Hi Brent.

There was something bouncing on the object it collided with … but it seems to make no difference …

I changed the body of the object that kills the problem object to this

physics.addBody(wallbottom,“static”,{density=1, friction=0.5,bounce=0})

And it still bounces … in fact I can see a difference in the problem …

If the spawned object has a high bounce value the problem is worsened.

I spawn with random bounce value like this:math.random(0.5, 1.7)

So in fact I could probably lower the high value to prevent the issue, but then I will miss out on some other effects I would like to obtain from the high bounce value.

I think I will make a simple example that does not have so much code around it, maybe from this you will be able to see what is my problem (but not until tomorrow YAWN it is late in Denmark ;-))

Hi @cwe,

One thing you may consider is using physics “contact” and pre-collisions. Then, when the object is about to hit another object which will kill it, you can tell Corona (for that specific collision) to use no bounce at all, even if the normal bounce of the object is higher.

Here’s a tutorial on the subject:

http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Hope this helps,

Brent

Hi Brent.

I will give it a go … I made a very simple test example and it for sure has this problem also, so it seems that it is not caused by some oddity somewhere else in my code.

I did experiment with the precollision already, but It seems that it is quite a bash to “performance”, and I get more than 10 precollision events for before I am finished with the animation/deacceleration …

Anyway I will give it a go with the event.contact to see if i will have more luck with this.

I will post when I have some news.

Thanks for the hint so far.

Hi @cwe,

If you set the linear velocity to 0 on collision, the body should stop immediately. Are there other objects that are colliding with the “dead” object and making it bounce a bit as the animation completes?

Regards,

Brent

Hi Brent.

There was something bouncing on the object it collided with … but it seems to make no difference …

I changed the body of the object that kills the problem object to this

physics.addBody(wallbottom,“static”,{density=1, friction=0.5,bounce=0})

And it still bounces … in fact I can see a difference in the problem …

If the spawned object has a high bounce value the problem is worsened.

I spawn with random bounce value like this:math.random(0.5, 1.7)

So in fact I could probably lower the high value to prevent the issue, but then I will miss out on some other effects I would like to obtain from the high bounce value.

I think I will make a simple example that does not have so much code around it, maybe from this you will be able to see what is my problem (but not until tomorrow YAWN it is late in Denmark ;-))

Hi @cwe,

One thing you may consider is using physics “contact” and pre-collisions. Then, when the object is about to hit another object which will kill it, you can tell Corona (for that specific collision) to use no bounce at all, even if the normal bounce of the object is higher.

Here’s a tutorial on the subject:

http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Hope this helps,

Brent

Hi Brent.

I will give it a go … I made a very simple test example and it for sure has this problem also, so it seems that it is not caused by some oddity somewhere else in my code.

I did experiment with the precollision already, but It seems that it is quite a bash to “performance”, and I get more than 10 precollision events for before I am finished with the animation/deacceleration …

Anyway I will give it a go with the event.contact to see if i will have more luck with this.

I will post when I have some news.

Thanks for the hint so far.

thanks, Brent! needed a disc to bounce only once at the end of its journey…worked for me!!!

function disc:preCollision( event )

if disc.y>myData._H*.85 then

event.contact.bounce = 0

end

end

disc:addEventListener( “preCollision” )

thanks, Brent! needed a disc to bounce only once at the end of its journey…worked for me!!!

function disc:preCollision( event )

if disc.y>myData._H*.85 then

event.contact.bounce = 0

end

end

disc:addEventListener( “preCollision” )

can any one help me with trajectory function i have

http://forums.coronalabs.com/topic/43378-object-not-stoping-in-my-trajectory-function/?p=225880
 

can any one help me with trajectory function i have

http://forums.coronalabs.com/topic/43378-object-not-stoping-in-my-trajectory-function/?p=225880