Help with Laser property definition
9 posts • Page 1 of 1
Help with Laser property definition
Hi, I hope this is correct section, I need some help with my situation.
There is a laser that should spawn an object (geom-B), when its ray hits another geometry (geom-A, generic, with specified collideSet).
I'd want to set a limit distance (X) between the laser and the geom-A. When the laser hits the geom-A below the distance X the laser should not spawn the geom-B, above the distance X the laser should spawn the geom-B.
The laser will be attached to a free moving object.
Is there a way to do this? Possibly without custom variables (my scripting level is veeery basic)?
Laser script (onLaserHit):
-------------------------------
(e)=>{
e.geom.density == 2 ? {
scene.addCircle({
radius = 1.5;
pos = e.pos;
}
})
} : {}
}
-------------------------------
Another question: why in Algodoo 2.1.0b5 the lasers change their properties (color and others) after spawning objects with this code? There wasn't this problem with older versions, or maybe I'm wrong?
Thanks
There is a laser that should spawn an object (geom-B), when its ray hits another geometry (geom-A, generic, with specified collideSet).
I'd want to set a limit distance (X) between the laser and the geom-A. When the laser hits the geom-A below the distance X the laser should not spawn the geom-B, above the distance X the laser should spawn the geom-B.
The laser will be attached to a free moving object.
Is there a way to do this? Possibly without custom variables (my scripting level is veeery basic)?
Laser script (onLaserHit):
-------------------------------
(e)=>{
e.geom.density == 2 ? {
scene.addCircle({
radius = 1.5;
pos = e.pos;
}
})
} : {}
}
-------------------------------
Another question: why in Algodoo 2.1.0b5 the lasers change their properties (color and others) after spawning objects with this code? There wasn't this problem with older versions, or maybe I'm wrong?
Thanks
- pfjeka
- Posts: 9
- Joined: Mon Feb 11, 2013 8:10 pm
Re: Help with Laser property definition
pfjeka wrote:I'd want to set a limit distance (X) between the laser and the geom-A. When the laser hits the geom-A below the distance X the laser should not spawn the geom-B, above the distance X the laser should spawn the geom-B.
Enter this into laser's script window command editbox:
- Code: Select all
_pos = {ro := readable(entity); gm := scene.entityByGeomID(ro.geom); a := gm.angle; r := ro.relPoint;
gm.pos + [(math.cos(a) * r(0) - math.sin(a) * r(1)), (math.cos(a) * r(1)) + math.sin(a) * r(0)]};
_dist = (hitPos) => {v := hitPos - _pos; (v(0)^2+v(1)^2)^0.5};
Now you have two additional property for laser:
_pos - laser position (you could check it works by entering _pos into script menu editbox)
_dist(point) - distance from laser to point
Use it in onLaserHit script as you need:
- Code: Select all
onLaserHit = (e)=>{ e.laser._dist(e.pos) < 10 ? {print("do spawn")}:{}}
(e)=>{
e.geom.density == 2 ? {
scene.addCircle({
radius = 1.5;
pos = e.pos;
}
})
} : {}
}
Another question: why in Algodoo 2.1.0b5 the lasers change their properties (color and others) after spawning objects with this code? There wasn't this problem with older versions, or maybe I'm wrong?
You wrong. You must to use ":=" instead of "=" in spawn script.
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
Re: Help with Laser property definition
Thank you Kilinich. I tried this code, but there is one problem: in console there is a message "WARNING - Failed to find entity with geom id: #0". How can I solve it?
The two new properties appear on the laser script menu. I don't know if it is important for the code you wrote, the geom-A should be an any geometry (only collideSet should be specific for collision with laser).
This is the code onLaserHit:
Can I add here also a second IF statement, that limits also the minimum speed of the geom-A, above which the geom-B is spawned? I mean, if at least one of two components of velocity (I don't need the relative velocity of the geom-A and laser) is bigger than the specified value, and if the distance between laser and geom-A is bigger than the specified value, the geom-B should be spawned.
I'm a bit stupid with Thyme...
The two new properties appear on the laser script menu. I don't know if it is important for the code you wrote, the geom-A should be an any geometry (only collideSet should be specific for collision with laser).
This is the code onLaserHit:
- Code: Select all
(e)=>{
e.laser._dist(e.pos) > 10 ? {
scene.addCircle({
radius := 1.5;
color := [1.0, 0.8, 0.0, 1.0];
pos := e.pos;
timeToLive := 0.1;
oncollide = (e)=>{
e.other.refractiveIndex := 1.4
}
})
} : {}
}
Can I add here also a second IF statement, that limits also the minimum speed of the geom-A, above which the geom-B is spawned? I mean, if at least one of two components of velocity (I don't need the relative velocity of the geom-A and laser) is bigger than the specified value, and if the distance between laser and geom-A is bigger than the specified value, the geom-B should be spawned.
I'm a bit stupid with Thyme...
- pfjeka
- Posts: 9
- Joined: Mon Feb 11, 2013 8:10 pm
Re: Help with Laser property definition
pfjeka wrote:Thank you Kilinich. I tried this code, but there is one problem: in console there is a message "WARNING - Failed to find entity with geom id: #0". How can I solve it?
Get last Algodoo version I suppose.
http://www.algodoo.com/forum/viewtopic.php?f=24&t=9381
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
Re: Help with Laser property definition
2.1.0.b7 gives the same result, with the same Warning message. It can't take the right ID...
So how could I combine two IF statements?
Thanks for patience
So how could I combine two IF statements?
Thanks for patience
- pfjeka
- Posts: 9
- Joined: Mon Feb 11, 2013 8:10 pm
Re: Help with Laser property definition
pfjeka wrote:2.1.0.b7 gives the same result, with the same Warning message. It can't take the right ID...
oh, geom 0 is background. I guess you put laser on background instead of some object
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
Re: Help with Laser property definition
pfjeka wrote:Can I add here also a second IF statement, that limits also the minimum speed of the geom-A, above which the geom-B is spawned? I mean, if at least one of two components of velocity (I don't need the relative velocity of the geom-A and laser) is bigger than the specified value, and if the distance between laser and geom-A is bigger than the specified value, the geom-B should be spawned.
use "and" operator for two condition check
() && ()
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
Re: Help with Laser property definition
You're right, I placed it on background for testing...
Now it works perfectly, thank you very much!
The last question, as one of conditions I must indicate the minimum velocity of geom-A to trigger the laser script. I need to indicate not the relative speed between geom-A and laser, but simply that when the modulus of one of two velocity components is bigger then a specified value, the condition is verified. I think is something like this (onLaserHit):
(e)=>{
((e.geom.vel)^2)^0.5 > [10, 10] ? {
scene.addCircle({
radius := 1.2;
refractiveIndex := 1;
pos := e.pos;
timeToLive := 0.12
})
} : {}
}
I know this is wrongest way to indicate it, this just to give idea.
Now it works perfectly, thank you very much!
The last question, as one of conditions I must indicate the minimum velocity of geom-A to trigger the laser script. I need to indicate not the relative speed between geom-A and laser, but simply that when the modulus of one of two velocity components is bigger then a specified value, the condition is verified. I think is something like this (onLaserHit):
(e)=>{
((e.geom.vel)^2)^0.5 > [10, 10] ? {
scene.addCircle({
radius := 1.2;
refractiveIndex := 1;
pos := e.pos;
timeToLive := 0.12
})
} : {}
}
I know this is wrongest way to indicate it, this just to give idea.
- pfjeka
- Posts: 9
- Joined: Mon Feb 11, 2013 8:10 pm
Re: Help with Laser property definition
Problem solved, I understood the notation of vectors in Thyme and added condition for modulus:
- Code: Select all
((e.geom.vel(0)^2 + e.geom.vel(1)^2)^0.5)
- pfjeka
- Posts: 9
- Joined: Mon Feb 11, 2013 8:10 pm
9 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests



