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?
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?
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 ;-))
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.
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.
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?
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 ;-))
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.
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.