Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Two Flying Animations - Hovering and Flying.

Bowr Udal
Registered User
Join date: 5 Dec 2005
Posts: 11
12-31-2008 21:20
I am building an avatar with wings and I have two animations; one animation with faster wing beats for hovering, where the arms move up and down for a vertically-oriented avatar, and a slower beat for when the avatar is flying and oriented horizontally.

I'm hardly a scripting guru but I have been editing this script and somehow managed to get the animations to stop when I am on the ground (it didn't at first). The problem that I keep having is that I can't predict which animation will play when I fly.

It usually begins with the horizontal flight animation and then *sometimes* I will start flapping faster (my hovering animation) and then my hovering animation won't stop until I land.

I hope I can get some feedback on this. Thanks a whole bunch!

Here is the code. It still has the notes from the original author in it:

CODE

// Cross Lament's Silly Animate-On-Flying Kludge

integer isFlying = FALSE ;

integer isHovering = FALSE;

integer hasperms = FALSE ;

key lastuser ;

default
{
state_entry()
{
llSetTimerEvent( 2 ) ; // Polling rate, check every couple of seconds
}

timer()
{
integer flystatus = llGetAgentInfo( llGetOwner() ) ;

// if the agent is flying, and the status holder says they're not...
if( ( flystatus & AGENT_FLYING ) && !isFlying && hasperms )
{
isFlying = TRUE ;
llStartAnimation( "flying" ) ;
}

// if the agent is NOT flying, and the status holder says they are...
else if( !( flystatus & AGENT_FLYING ) && isFlying && hasperms )
{
isFlying = FALSE ;
llStopAnimation( "flying" ) ;
}

// if the agent is flying, and the status holder says they're not...
else if( ( flystatus & AGENT_IN_AIR ) && !isHovering && hasperms )
{
isHovering = TRUE ;
llStartAnimation( "hovering2" ) ;
}

// if the agent is NOT flying, and the status holder says they are...
else if( !( flystatus & AGENT_IN_AIR ) && isHovering && hasperms )
{
isHovering = FALSE ;
llStopAnimation( "hovering2" ) ;
}
}

attach( key id )
{
if( ( id != NULL_KEY ) && !hasperms )
{
lastuser = id ;
llRequestPermissions( id, PERMISSION_TRIGGER_ANIMATION ) ;
}

else if( id = NULL_KEY )
{
hasperms = FALSE ;

integer i ;
list animlist = llGetAnimationList( lastuser ) ;

for( i = 0; i < llGetListLength( animlist ); i++ )
{
llStopAnimation( llList2String( animlist, i ) ) ;
}
}
}

run_time_permissions( integer perms )
{
if( perms & PERMISSION_TRIGGER_ANIMATION )
{
hasperms = TRUE ;
}

else
{
llWhisper( 0, "Warning: Animation permission not set!" ) ;
}
}
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
01-01-2009 03:38
Two things:
1.
When Agent is in air it may be flying or hovering.
When Agent is flying it is in air.
So when you test for hovering you must test for flying as well, to make sure it is not flying.
2.
I would stop the hover animation when I start the fly animation and vice versa.
_____________________
From Studio Dora
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
01-01-2009 06:22
Foremost I would use llGetAnimation in preference to llGetAgentInfo - it's not particularly intuitive but llGetAnimation will always return the basic animation state regardless of the actual animation.

Bare bones example:

CODE

float timerEventLength = 0.1;
string lastAnim;
string lastAnimState;

default
{
attach(key id)
{
if (id != NULL_KEY)
{
lastAnim = "";
lastAnimState = "";
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llSetTimerEvent(timerEventLength);
}
}

timer()
{
string curAnimState = llGetAnimation(llGetOwner());

if (curAnimState != lastAnimState)
{
if (lastAnim != "")
{
llStopAnimation(lastAnim);
lastAnimState = "";
lastAnim = "";
}
if (llGetSubString(curAnimState, 0, 7) == "Hovering")
{
llStartAnimation("hovering2");
lastAnim = "hovering2";
}
else if (llGetSubString(curAnimState, 0, 5) == "Flying")
{
llStartAnimation("flying");
lastAnim = "flying";
}

lastAnimState = curAnimState;
}
}
}
Bowr Udal
Registered User
Join date: 5 Dec 2005
Posts: 11
01-01-2009 15:49
Thank you Dora, that's kind of what I suspected.

Thanks Pale Spectre, I tested the code that you wrote and it works perfectly! And it's much shorter, too.