Page 1 of 1

Better way than using a laser

PostPosted: Tue Dec 19, 2017 5:33 am
by eeieeio
Hi,

In some of the scenes I have been creating there comes a time when I need to make an object disappear. Up until now I have been using a laser and setting the object timetoLive = 0 on hit by laser. I try to hide the laser using various methods but I'm thinking there must be a better way. What is the best way to make an object disappear? Thanks for your input.

Dave

Re: Better way than using a laser

PostPosted: Tue Dec 19, 2017 2:41 pm
by Kilinich
That depends on what you want to be trigger for object to disappear?
If it a key - there is a build-in "destroy key" in control menu.
If it's a collision - you could use some scene.my. variable and postStep script to kill objects.
If it's some area - easiest way is to make killer geom.
etc.

Re: Better way than using a laser

PostPosted: Fri Dec 29, 2017 8:06 pm
by FRA32
Hey eeieeio, it seems you have been using script's for your idea without realizing the potential it actually has. It is very simple to extend events like the removal of objects to much better scenarios than laser hit's once you understand the other (e)=>{} event's that exist.
If you like to remove objects using collisions, either use the killer attribute, or you use onCollide in one of the objects and type the command in. If you want an object to remove OTHER objects, you type e.other.timetolive = 0; if you want an object to be REMOVED by other objects, you type timetolive = 0. The difference is the object whose timetolive is set to 0, thus changing the exact behavior of the collision.
You can also make objects dissappear when hit by lasers as you did, using onLaserHit(e.geom.timetolive = 0) or onHitByLaser(timetolive = 0). You could click on objects using onClick(timetolive = 0), however the most universal method in my opinion of removing objects is via poststep. The only drawback is that poststep does not interact with it's surrounding world like collisions do, and solely act's using properties of the object and global variables like scene.my... variables. The advantage is that you can trigger many things, including removal, just by checking certain conditions, for example whether the object is far away from the origin or not, or if the simulation time exceeds a certain time.
If you want to remove objects even when the Simulation is PAUSED, you can use the "update" box to execute code all time, independent of the simulation. That can often be a drawback too, especially if you ever use other scripts that depend a lot on the time that passes between executions, like artificial forces etc.

If you specify what exactly you'd like to do, we could in return give more precise answers.

Re: Better way than using a laser

PostPosted: Fri Dec 29, 2017 11:05 pm
by eeieeio
FRA32,

That was extensive answer to my simple question. I appreciate the time and effort you put into it. I am working on a Ball Clock. It's called Dave's Algodoo Ball Clock under user eeieeio in Algobox. I use onClick to spawn a laser aimed at one of the balls and set the balls' timetoLive = 0 onHitByLaser so the user, by clicking the button, can remove balls from the minutes, or hours row of balls to set the clock to the current time. In order to hide the laser, I set its timetoLive at .25 seconds and set its color:= [0.005, 0.005, 0.005, 1.0];. To add balls I use Scene.addCircle.

I use onHitByLaser to release the balls at the appropriate time by firing a laser at a gate that is holding the balls back. Again, I tried to hide the method I am using from the user by coloring the gate black and it is on a black background. In this case, the laser is 'fired' by one of the balls rolling over a hidden box (onCollide) along the path that the ball rolls along.

I was not able to attach my example for you so I posted it on Algobos. It can be found under user eeieeio or search for "example for FRA32" It is a scene that I created for the purpose of demonstrating what I am referring to.In the first two paragraphs above. In the example scene, there is no attempt to hide my methods.

Thanks, Dave
eeieeio

Re: Better way than using a laser

PostPosted: Sun Jan 14, 2018 3:27 am
by Fastpulse91
hi,

how i know the wavelenght's laser, in scripting mode?

thK

Re: Better way than using a laser

PostPosted: Mon Jan 15, 2018 12:03 pm
by Kilinich
Fastpulse91 wrote:how i know the wavelenght's laser, in scripting mode?


There is no way to get actual laser ray color after lens, you could only get original via e.laser.color in onHitByLaser.