Help with delay code
3 posts • Page 1 of 1
Help with delay code
Hi, I'm making a simple thyme gun for a main tank cannon. A box, when hit by a laser, spawns a circle with a given speed. To shoot i should activate the laser with a key.
Problem: if I hold down the laser activation key, there will be a lot of objects spawned. I need to spawn only one object every X seconds, to have a slow, controlled rate of fire. I'm sure someone has already solved this problem in the past.
How can I implement this function in the laser, o in the spawning box? The spawning code is actually in the box.
I read different things about delays, timers and other things, but I can not do anything that works. I know I could make a mechanical delayer (like a circle with slow speed motor), but I prefer to do a script, to have less objects in the scene.
Thank you.
Problem: if I hold down the laser activation key, there will be a lot of objects spawned. I need to spawn only one object every X seconds, to have a slow, controlled rate of fire. I'm sure someone has already solved this problem in the past.
How can I implement this function in the laser, o in the spawning box? The spawning code is actually in the box.
I read different things about delays, timers and other things, but I can not do anything that works. I know I could make a mechanical delayer (like a circle with slow speed motor), but I prefer to do a script, to have less objects in the scene.
Thank you.
- pfjeka
- Posts: 9
- Joined: Mon Feb 11, 2013 8:10 pm
Re: Help with delay code
For laser:
- Code: Select all
_lastShot = 0
_delay = 5
onLaserHit = (e) => {
(sim.time > e.laser._lastShot + e.laser._delay) || (e.laser._lastShot > sim.time) ? {
//do shot
e.laser._lastShot = sim.time
} : {}
}
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
3 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests



