How to delete objects using a script
Posted: Tue Apr 21, 2015 1:44 am
At first, I was having trouble with figuring out how to delete objects with a script. After some experimentation, it seems that the perfect way to do it is to set an object's timeToLive property equal to 0.
I crossed this problem when I decided to program a star to absorb the mass of any planetary object that hit it, and the code for the star's onCollide event looks like this:
As you can see, I'm deleting the other circle's instance by eliminating all the time it has to live.
Anyway, I hope this is useful to anyone who's new to programming with Algodoo! (I'm new myself)
I crossed this problem when I decided to program a star to absorb the mass of any planetary object that hit it, and the code for the star's onCollide event looks like this:
- Code: Select all
(e)=>{
radius = math.sqrt(radius ^ 2 + (e.other.density / density) * e.other.radius ^ 2);
e.other.timeToLive = 0
}
As you can see, I'm deleting the other circle's instance by eliminating all the time it has to live.
Anyway, I hope this is useful to anyone who's new to programming with Algodoo! (I'm new myself)