Better way than using a laser

Discuss how to have fun with Algodoo, how to create games, and entertaining scenes.

Better way than using a laser

Postby eeieeio » Tue Dec 19, 2017 5:33 am

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
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm

Re: Better way than using a laser

Postby Kilinich » Tue Dec 19, 2017 2:41 pm

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.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Better way than using a laser

Postby FRA32 » Fri Dec 29, 2017 8:06 pm

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.
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm

Re: Better way than using a laser

Postby eeieeio » Fri Dec 29, 2017 11:05 pm

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
eeieeio
 
Posts: 25
Joined: Thu Nov 30, 2017 7:02 pm

Re: Better way than using a laser

Postby Fastpulse91 » Sun Jan 14, 2018 3:27 am

hi,

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

thK
Fastpulse91
 
Posts: 3
Joined: Sun Jan 14, 2018 1:29 am

Re: Better way than using a laser

Postby Kilinich » Mon Jan 15, 2018 12:03 pm

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.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Algodoo for fun

Who is online

Users browsing this forum: No registered users and 2 guests