homing device
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
05-07-2007 09:17
I have a jeep. I would like to add some "homing" script that beeps (or something) as it gets closer to a known object (x,y,z).
Can anyone point me to a script that does something like this that I can modify.
Thanks
|
|
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
|
sue dough code...
05-07-2007 12:58
vector T = < x,y,z>; float close=255;
default { state_entry() { llSettimerEvent(10); }
timer(...) { if( llVecDist( llGetPos(), T) < close ) { ***Beep*** close = llVecDist( llGetPos(), T); } }
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
05-08-2007 06:52
great! thanks..I will go give this a try.
|
|
Lucius Nesterov
Registered User
Join date: 12 Oct 2006
Posts: 33
|
05-08-2007 09:13
My interpretation was that Nichiren wanted something more like a Geigger counter. Maybe just keep checking the distance and altering a timer interval, like: vector T = < x,y,z>;
default { state_entry() { // Just to get the timer going llSetTimerEvent(1); }
timer(...) { // Get the current distance to target float dist = llVecDist( llGetPos(), T); // Make the beep noise
// Set pause before next beep if (dist < 1) llSetTimerEvent(0.2); else if (dist < 3) llSetTimerEvent(0.4); else if (dist < 5) llSetTimerEvent(1.0); else if (dist < 9) llSetTimerEvent(2.0); else llSettimerEvent(3.0); } }
Or do some maths to convert the target distance to a time interval, so you get a smoother transition, e.g. timePulse = dist/10.0. Be sure to set a reasonable lower limit though; it could already be a lag-inducing script.
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
05-09-2007 14:16
Getting error :name not defined within scope on the last ELSE statement. I noticed that the SettimerEvent on that line is not colored liked the ELSE IF statements. any clue what is wrong?
vector T = < 118,245,57>; float gap = 2.0;
default { state_entry() { // Just to get the timer going llSetTimerEvent(gap); }
timer() { // Get the current distance to target float dist = llVecDist( llGetPos(), T); // Make the beep noise
// Set pause before next beep if (dist < 1) llSetTimerEvent(0.2); else if (dist < 3) llSetTimerEvent(0.4); else if (dist < 5) llSetTimerEvent(1.0); else if (dist < 9) llSetTimerEvent(2.0); else llSettimerEvent(3.0); } }
|
|
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
|
05-09-2007 14:19
else llSettimerEvent(3.0); should probably be else llSetTimerEvent(3.0); 
_____________________
Send me the last 4 digits of a valid SSN, I'll verify you are who you say you are, even if you aren't.
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
05-10-2007 11:04
Yup..that was it...ugh...must have been late at night. thx I am going to try and modify to that the user can activate and deactive now..
|
|
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
|
05-10-2007 11:25
modified to use touch as a start/stop mechanism. vector T = < x,y,z>; integer running=1;
default{ state_entry(){ // Just to get the timer going llSetTimerEvent(1); }
timer(...){ // Get the current distance to target float dist = llVecDist( llGetPos(), T); // Make the beep noise
// Set pause before next beep if (dist < 1) llSetTimerEvent(0.2); else if (dist < 3) llSetTimerEvent(0.4); else if (dist < 5) llSetTimerEvent(1.0); else if (dist < 9) llSetTimerEvent(2.0); else llSetTimerEvent(3.0); }
touch_start(integer touches){ integer i=0; do{ if(llDetectedKey(i)==llGetOwner()){ if(running){ llSetTimerEvent(0); running=0; }else{ llSetTimerEvent(1); running=1; } } i++; } while(i<touches); }
}
_____________________
Send me the last 4 digits of a valid SSN, I'll verify you are who you say you are, even if you aren't.
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
05-10-2007 12:42
Thanks..I will go try this now.
I have also played with trying to turn the beeping off if it is out of reasonable distance. For some reason the code below turns it off..but permanently. even when I am right on the x,y,z. due..to the >9 statement.
// Set pause before next beep if (dist < 1) llSetTimerEvent(0.2); else if (dist < 3) llSetTimerEvent(0.4); else if (dist < 5) llSetTimerEvent(1.0); else if (dist > 9) llSetTimerEvent(0);
else llSetTimerEvent(3.0);
|
|
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
|
05-10-2007 13:47
Yep setting timer to 0 turns it off.
|
|
Lucius Nesterov
Registered User
Join date: 12 Oct 2006
Posts: 33
|
05-12-2007 03:40
Did you solve your problem?
Don't call llSetTimer(0) or it will never enter the timer funciton again to check distance. Instead just use an IF statement to stop it playing the sound over a certain distance.
e.g.
if (dist<9) llPlaySound(...);
|