On/Off OnLaserHit?
7 posts • Page 1 of 1
On/Off OnLaserHit?
Hi everyone,
I apologise in advance if this has already been asked - I couldn't find it, but maybe I'm just useless at searching.
If I use OnLaserHit to change a variable, then since it is merely registering a hit it will just change the value, then do nothing else. What I am after is a way to make the laser actually see if it is hitting anything real-time, and change the variable accordingly. This piece of code (It's just made up, it doesn't do anything!) shows what I want to do fairly well, I think:
Can anyone help me with this?
Thanks,
Torn
I apologise in advance if this has already been asked - I couldn't find it, but maybe I'm just useless at searching.
If I use OnLaserHit to change a variable, then since it is merely registering a hit it will just change the value, then do nothing else. What I am after is a way to make the laser actually see if it is hitting anything real-time, and change the variable accordingly. This piece of code (It's just made up, it doesn't do anything!) shows what I want to do fairly well, I think:
- Code: Select all
(e)=>{LaserHit == true ? {scene.my.whateverthevariableis = 1} : {scene.my.whateverthevariableis = 0}}
Can anyone help me with this?
Thanks,
Torn
- Torn
- Posts: 32
- Joined: Tue Sep 01, 2009 8:06 am
Re: On/Off OnLaserHit?
Torn wrote:Hi everyone,
I apologise in advance if this has already been asked - I couldn't find it, but maybe I'm just useless at searching.
If I use OnLaserHit to change a variable, then since it is merely registering a hit it will just change the value, then do nothing else. What I am after is a way to make the laser actually see if it is hitting anything real-time, and change the variable accordingly. This piece of code (It's just made up, it doesn't do anything!) shows what I want to do fairly well, I think:
- Code: Select all
(e)=>{LaserHit == true ? {scene.my.whateverthevariableis = 1} : {scene.my.whateverthevariableis = 0}}
Can anyone help me with this?
Thanks,
Torn
Using a system involving two lasers, you could build something that checked if the time value (updated by the laser unattached to the object) was before the current time (+ 0.05s or something), and if it was it would change the time.
This isn't built in , just a note though, in future if you're checking if <x> == true or <x> == false then use just <x> or ! <x> (respectively), the thyme parser will know what you're on about that way (if a man came up to you and asked "is true equal to true?", you might be a bit confused, or if they asked "is true equal to false?").
It is possible if you know what you're doing to calculate these kinds of things and take appropriate action, but it's easier to just use two lasers to get the job done .
- gradyfitz
- Posts: 174
- Joined: Tue Sep 01, 2009 8:33 am
- Location: Victoria, Australia
Re: On/Off OnLaserHit?
Ok, thanks. How would I go about making this time-checking code that you mentioned? I have a reasonable grip on Thyme, but I'm not sure how to approach these more complex things.
- Torn
- Posts: 32
- Joined: Tue Sep 01, 2009 8:06 am
Re: On/Off OnLaserHit?
Torn wrote:Ok, thanks. How would I go about making this time-checking code that you mentioned? I have a reasonable grip on Thyme, but I'm not sure how to approach these more complex things.
A simple code like
- Code: Select all
(e)=>{eval("Scene.my.ExampleValue = {Sim.time < " + (Sim.time + 0.05) + "}")}
would do the trick, it has a 0.05s area for changing to false . Hopefully it helps.
- gradyfitz
- Posts: 174
- Joined: Tue Sep 01, 2009 8:33 am
- Location: Victoria, Australia
Re: On/Off OnLaserHit?
Hi
Nice piece of code. But i cant get it to work. So, what i wanna do is that if its TRUE, something is gonna happen, for example a motor speed changes to 5. And if it sets to FALSE the motor speed will be 0. Here is a pic what i mean:
Nice piece of code. But i cant get it to work. So, what i wanna do is that if its TRUE, something is gonna happen, for example a motor speed changes to 5. And if it sets to FALSE the motor speed will be 0. Here is a pic what i mean:
- probber
- Posts: 5
- Joined: Tue Sep 15, 2009 9:12 pm
- Location: Germany
Re: On/Off OnLaserHit?
In Algodoo booleans are understood. You don't need to compare them to true or false, it will do it for you.
- Code: Select all
Scene.my.bool ? {Scene.my.m = 5} : {Scene.my.m = 0}
-
standardtoaster - Posts: 606
- Joined: Mon Aug 31, 2009 7:57 pm
Re: On/Off OnLaserHit?
Good to know that *g. Thanks, works fine
- probber
- Posts: 5
- Joined: Tue Sep 15, 2009 9:12 pm
- Location: Germany
7 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests