Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Detecting Landing/Flying?

ragarth Doolittle
Registered User
Join date: 18 Nov 2005
Posts: 28
01-25-2006 01:28
If I have a script that I want to run when my character starts to fly, then stops flying, how would I detect those events?
Nepenthes Ixchel
Broadly Offended.
Join date: 6 Dec 2005
Posts: 696
01-25-2006 01:36
I did this in a script by polling the animation being played and checking if it was a flying or non-flying animation. I was just on my way to these forums to see if there was a better way, because I figure the constant polling can't be an efficent use of sim resources.
SunenRec Ayoob
Registered User
Join date: 29 Dec 2004
Posts: 61
01-25-2006 03:16
Sounds like llGetAgentInfo is what you're looking for :)
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-25-2006 03:58
Yeah, llGetAgentInfo is what you want to use - I think the important question is how and when. If you want to detect auto landing when people fly downwards onto the ground or auto-takeoff when they hold up, you could take control of the up and down keys (but pass them through as well so people can still move) and test llGetAgentInfo then. This is more efficient than using a timer as it's not pinging all the time.

However that wouldn't detect it if somebody just pressed "F" to change into or out of flight mode. I think you'd need a timer for that. Set it with a fairly long rate, not every 0.1 seconds or something, unless it's really critical that the animation stops or starts instantly.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
I've already done this...
01-25-2006 06:22
In Cyberflight, it has to decide when you're flying, when you're falling, and when you're jumping. And in my "automatic" wings (which I really ought to package up and add to my vendor pile) I had to do the same thing.

Basically, you need to use all three. Three? Yep:

Check on command and on timer and in on_rez, so that you'll get the check right away when you connect or teleport. :)
Lightwave Valkyrie
Registered User
Join date: 30 Jan 2004
Posts: 666
01-25-2006 10:49
CODE
integer isFlying = FALSE;

particlesystemfunction()
{
// Your cute particle system code goes here as a function!
}

default
{
state_entry()
{
llSetTimerEvent( 2 ) ;
}

timer()
{
if( (llGetAgentInfo( llGetOwner() ) & AGENT_FLYING) && !isFlying )
{
particlesystemfunction() ; //IsFlying
isFlying = TRUE;
}

else if( !(llGetAgentInfo( llGetOwner() ) & AGENT_FLYING) && isFlying )
{
llParticleSystem( [] ) ; //is not Flying
isFlying = FALSE;
}
}
}

this is set up for particles but you can change it to do what you want
-LW
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-26-2006 04:10
Anyone, plz tell me why llGetAgentInfo is better than llGetAnimation?
_____________________
:) Seagel Neville :)
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
01-26-2006 05:05
From: Seagel Neville
Anyone, plz tell me why llGetAgentInfo is better than llGetAnimation?
I think mostly because the Av could be wearing an AO replacing the basic flying animations.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-26-2006 10:27
From: Ben Bacon
I think mostly because the Av could be wearing an AO replacing the basic flying animations.
Ben, make sure llGetAnimation. It is the current basic animation state to return, not the current firing animation. So if you forced your avatar to stand by your AO when it sat, "Sitting" state would be returned. Therefore, everybody says this function is unusable. But my point of view, this is unusable because of being so similar as to be substituted for llGetAvatarInfo.
_____________________
:) Seagel Neville :)
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
01-26-2006 10:55
Ah - I see what u mean Seagel.
Thanks for the info.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-26-2006 11:51
I just put my "hide wings while flying" script out in a new L$1 box at Skyhook Station (LostFurest dAlliez, 100,10,520 or thereabouts). It's similar to Lightwave's script, but it only turns the "flying" state off when you're not flying *or* in the air. I tried it both ways and that seemed to look better if you didn't turn off the "flying" state until you actually landed.

The reason I use llGetAgentInfo() is because you need to do more checks if you use llGetAnimation(), which means more LSL code: you have to check for any one of: Hovering, Hovering Down, Hovering Up, Flying, FlyingSlow, and if you wait until you finish landing Soft landing and Falling Down if you had previously been flying. You can put these in a list and use llListFindList( FLYING_ANIMS, llGetAnimation() ), but llGetAgentInfo() is simpler.
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-26-2006 19:34
Ben, not at all.
Argent, thank you. I'm pleased that I found someone use that function except me. :)
_____________________
:) Seagel Neville :)
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
01-26-2006 20:13
Id rather do this:
CODE

default { // On ground
state_entry() {
// Code to exec when avatar stops flying goes here.
}
attach(key id) {
if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
state flying;
}
moving_start() {
if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING)
state flying;
}
}
state flying {
state_entry() {
// Code to exec when avatar starts flying goes here.
}
attach(key id) {
if (!(llGetAgentInfo(llGetOwner()) & AGENT_FLYING))
state default;
}
moving_start() {
if (!(llGetAgentInfo(llGetOwner()) & AGENT_FLYING))
state default;
}
}

Youre going to have to wear this as an attachment, though it cuts down on unnecessary timer events.
==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
01-27-2006 00:11
From: Christopher Omega
Youre going to have to wear this as an attachment, though it cuts down on unnecessary timer events.
==Chris
:eek: I've learnd this. Thank you, Chris. :)
_____________________
:) Seagel Neville :)
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-27-2006 08:05
From: Christopher Omega
moving_start()
Oh, now that's a good tweak. You may want to have the return to default happen when you're not in the air rather than not flying in some cases.
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
01-27-2006 08:11
Very clever, Chris. I'll be converting some of my stuff to use that technique instead of timers.