Turn on/off process when certain height from the ground
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
06-13-2006 20:32
I'm Stumped here.
I am trying to make a switch (on/off) based on whether of not the object is within a certain height.
For example:
Object higher than 30m from the ground = off
Object not higher than 30m from the ground = on
I know that I wanna use llGround and GetPos, but and unsure how to go about it.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-13-2006 21:03
Well, you use llGround to get the height of the ground, then llGetPos to get your height, and then find the difference to see how high you are above the ground. vector groundVector = llGround(ZERO_VECTOR); // ZERO_VECTOR because I want to find the ground vector directly under me
float groundHeight = groundVector.z; // Now get the height part of that vector
vector myPos = llGetPos(); // Next, find my own position...
float myHeight = myPos.z; // ... and find the height part of that
float myHeightAboveGround = myHeight - groundHeight; // The difference between the two, is how high I am above the ground
if (myHeightAboveGround > 30.0) { // do something } else { // do something else }
Did that answer your question?
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
06-14-2006 04:02
Yes Nice!
I think alot of folks could benefit from this.
I'm using this script to turn on/off a particle script once my airplane gets close to the ground.
I knew what functions to use but was unsure how to slap the math into script form.
Thanks alot!
|
|
Trent Hedges
TrentCycle & GRAPHICA
Join date: 4 Sep 2003
Posts: 198
|
06-14-2006 08:27
Hey Johnny - they beat me to it - i got this working last night too for my 'ground dusting' on my hover vehicle. I made mine exactly as described above and it works beautifully - I also added a small script to detect collisions from the underside so that when you land on a rooftop or building you get a dusting effect there too - works nicely on roads etc where you might be above land.
hope that helps!
Cheers, Trent
|
|
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
|
06-14-2006 11:13
As an additional note, another layer of altitude checking can give you different ground effects for being over ground or over water. Good times.
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
06-14-2006 14:55
From: Trent Hedges Hey Johnny - they beat me to it - i got this working last night too for my 'ground dusting' on my hover vehicle. I made mine exactly as described above and it works beautifully - I also added a small script to detect collisions from the underside so that when you land on a rooftop or building you get a dusting effect there too - works nicely on roads etc where you might be above land.
hope that helps!
Cheers, Trent Hey ...I want colllision detection. LOL
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
06-14-2006 17:08
Well I think this is a good script in the right direction but I noticed that this doesnt work as a constant. Lemmie give ya the script and see if you can tell me why it hangs. The "Ground Duster" script it is referring to is the ground dust ...heh nothing more than a particle script set default on. This is how it is supposed to work..lol If in ON (default state ) and the object is within 8-10 Ft from the ground.. turn on "Ground Duster" and particles If engine is off (off state) then listen for the message to tell it to put it in default state which in turn starts the process over again. The problem is I think the process is getting stuck in the While status. You will see how I simplified the variables listen in Ziggy's script above. default { state_entry() { vector myPos = llGetPos() - <0,0,llGround(ZERO_VECTOR)>; float myHeightAboveGround = myPos.z; llListen( 250, "", NULL_KEY, "" ); if (myHeightAboveGround > 4.0) { llSetScriptState("Ground Duster", TRUE); } else { llSetScriptState("Ground Duster", FALSE); } } listen(integer channel, string name, key id, string message) { vector myPos = llGetPos() - <0,0,llGround(ZERO_VECTOR)>; float myHeightAboveGround = myPos.z; if ((message) == "on") { if (myHeightAboveGround > 4.0) { llSetScriptState("Ground Duster", TRUE); } } if ((message) == "off") { llSetScriptState("Ground Duster", FALSE); state off; } } } state off { state_entry() { llListen( 250, "", NULL_KEY, "" ); } listen(integer channel, string name, key id, string message) { vector myPos = llGetPos() - <0,0,llGround(ZERO_VECTOR)>; float myHeightAboveGround = myPos.z; if ((message) == "on") { if (myHeightAboveGround > 4.0) { llSetScriptState("Ground Duster", TRUE); state default; } } } }
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-14-2006 17:24
If the other script starts particles, and you then turn the script off, I don't think the particle system will stop. I know the particles stay if you delete the script, because they become a property of the prim. The only way to turn off particles is to make an empty call: llParticleSystem([]); So instead of turning the other script on and off, you could try sending it a link message, and then add a link message handler to the other script which creates the particles, and explicitly turns them off, on command. And I used long variable names and lots of steps in my script to explain the math that was going on. I figured you'd find a way to write it more efficiently once you understood it  Also, in this script, in the on state... you only check for your height when the script starts for the first time (state_entry) and when you receive the "on" command (listen). So if you're above 4.0m when you receive the on command, you won't turn on the duster, but after that if you get within range, there's nothing that detects that. I think the script needs to be structured something like this. I'm assuming that the script starts out in the "on" state, which is what your script does now. default { state_entry() -- Turn on listener -- Start a timer, say a 10 second timer
timer() -- Check object height. If it's in range, send link message to other script to turn on duster. If it's outside range, send link message to other script to turn off duster. You could make this more efficient by using a variable to remember the last state, so you only send a message when the state changes, and not on every timer tick
listen() -- On command - do nothing, since you're already checking every 10 seconds -- Off command - go to off state }
state off { state_entry() -- Turn off timer -- Send message to duster script to turn off, since you want it off regardless of height -- Turn on listener
listen() -- On command - go to default state }
Something like that... I'm too lazy to write real code. Hope that made sense 
|
|
Johnny Mann
Registered User
Join date: 1 Oct 2005
Posts: 202
|
06-14-2006 17:36
It made sense.
The reason I have it responding to "on" is because that is the link message from the pilot seat to alert the engine to start up.
I do like the idea of the timer. Mine would have to be more sensor speed. Can you speed up the timer more than 1 sec?
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-14-2006 17:46
You can, but it doesn't make sense to speed it up too much. One, you'll put a heavy load on the sim, which these days means the sim will slow your script down to ensure that everything else runs smoothly. So you might end up with a laggy vehicle because you're trying to get some fancy effects. Two, it'll take some time to start up the particles anyway, so have a very fast check doesn't really make sense.
Anyway, to try it, use something like llSetTimerEvent(0.5);
You should also try and make it smart enough to not keep turning the particles on/off if the vehicle is hovering right around the 4m altitude, i.e. its changing quickly between being in range and being out of range. Again, this is bad for the sim, and the visual effect will be pretty strange too. If you have a slower timer, you don't have to worry about this, because you know that it won't change faster than the timer tick.
|