Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Flight Assist

Morph Wollongong
Not a Copy
Join date: 19 May 2006
Posts: 13
09-03-2006 09:18
The following is a script suitable for a simple HUD. To experiment with it, you can create a 10m X 0.01m X 0.01m blank-texture semi-transparent box, put this script in it and attach the box to a convenient HUD attachment point.

The comments have a short summary of the operational highlights.

Contains bug fixes due to reports up through 14-Dec-2006

CODE

//
// Flight Assist Example
//
// Highlights:
// - altitude-based assist (lower altitude == less assist, higher == more)
// - horizontal movement gets relatively less assist than vertical.
// - HUD color indication of movement mode
// - brown: not flying (i.e. earth)
// - green: flying w/ assist
// - white: hovering w/ assist
// - black: assist disabled


// gAssistParams enables altitude-based flight assist. Lower altitudes
// will get less momentum assist so that the client updating overhead
// is less likely to harm controllability. Plus it's a pain to collide
// with a building at high speed in a damage-enabled area.
//
// see increaseMomentumAssist() for more info
//
list gAssistParams = [ <1.1, 100, 200>, <1.25, 1000, 800>, <1.4, 10000, -1> ];
float gInc = 0.1; // The increment to add to the momentum assist parameter on the next control key event
float gMass; // current mass (assuming it's constant; can imagine a variable mass assist tho :-) )
integer gMotor = FALSE; // Indicates whether momentum assistance is on
integer gAgentInfo; // A bitmask of the agent/avi current state
integer gReqKeys; // A bitmask of the control keys required to operate
integer gReqPerms; // A bitmask of the required permissions to operate
key gWearer; // UUID of the avi who is wearing this attachment

float gMomentumAssist = 0; // The current applied momentum assist
float increaseMomentumAssist(vector pos)
{
integer iii;
integer len;

len = llGetListLength(gAssistParams);
vector aParams;
for (iii = 0; iii < len; iii++)
{
aParams = llList2Vector(gAssistParams, iii);
if (pos.z < aParams.z)
{
jump exitLoop;
}
}
@exitLoop;

if (gMomentumAssist < aParams.y)
{
gInc *= aParams.x; // increase momentum assist exponentially
// param values closer to 1 result in slower growth
gMomentumAssist += gInc;
}
else
{
gMomentumAssist = aParams.y;
}

return gMomentumAssist;
}

vector getForwardDir()
{
vector ret;

ret = <1,0,0>*llGetCameraRot(); // camera rotation leads forward direction; so use it to direct assist
ret.z = 0;

return llVecNorm(ret);
}

getPermissions()
{
if ((llGetPermissions() & gReqPerms) == gReqPerms)
{
llTakeControls(gReqKeys, TRUE, TRUE);
}
else
{
llRequestPermissions(gWearer, gReqPerms);
}
}

gotControlInput(integer held)
{
gAgentInfo = llGetAgentInfo(gWearer);

if (!(held & gReqKeys))
{
if (gAgentInfo & AGENT_FLYING)
{
state hover;
}
}

if (gAgentInfo & AGENT_FLYING)
{
if (held & gReqKeys)
{
vector p = llGetPos();
vector dir;
float assist;

assist = increaseMomentumAssist(p);

if (p.z > llGround(ZERO_VECTOR)+50.0)
{
llSetBuoyancy(1.0);
}
else
{
// For some reason, if you are below
// llGround()+50.0 meters, you will
// slowly rise to that height if you
// llSetBuoyancy(1.0). An avatar can maintain
// hover below this height w/o assist; so
// no buoyancy change.
llSetBuoyancy(0.0);
}

if (held & CONTROL_FWD)
{
dir = getForwardDir();
// flying too fast horizontally
// typically makes the avatar
// uncontrollable since lag is
// high due to heavy updates;
// Do a simple reduction of assist
assist /= 3.0;
}
else if (held & CONTROL_BACK)
{
dir = -getForwardDir();
assist /= 3.0;
}
else if (held & CONTROL_UP)
{
dir = <0,0,1>;
}
else if (held & CONTROL_DOWN)
{

dir = <0,0,-1>;
}

llPushObject(gWearer, assist*gMass*dir, ZERO_VECTOR, FALSE);

gMotor = TRUE;
}
}
}

onAttach(key avatar)
{
gWearer = avatar;
if (gWearer != NULL_KEY)
{
getPermissions();
}
}

default
{
state_entry()
{
gReqKeys = CONTROL_FWD | CONTROL_UP | CONTROL_DOWN | CONTROL_BACK;
gReqPerms = PERMISSION_TRACK_CAMERA|PERMISSION_TAKE_CONTROLS;
gMass = llGetMass();
llSetColor(<0,1,0>, ALL_SIDES);

// Check if HUD is already attached
gWearer = llGetOwner(); // for now
if (llGetAttached() != 0)
{
getPermissions();
}

llSetTimerEvent(0.1);
}

on_rez(integer param)
{
llResetScript();
}

attach(key agent)
{
onAttach(agent);
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(gReqKeys, TRUE, TRUE);
}
}

touch_start(integer num)
{
state disabled;
}

control(key owner, integer held, integer change)
{
gotControlInput(held);
}

timer()
{
gAgentInfo = llGetAgentInfo(gWearer);

if (!(gAgentInfo & AGENT_FLYING))
{
state landed;
}
}
}

state hover
{
state_entry()
{
llSetColor(<1,1,1>, ALL_SIDES);

gMotor = FALSE;
gMomentumAssist = 0;
gInc = 0.1;
// adjust a little for lag
llMoveToTarget(llGetPos(), 0.1);
vector pos = llGetPos();
// you can hover unassisted at ground level + 50 meters
// in fact, if you set buoyancy to 1.0 there, you will slowly
// rise to ground level + 50 meters
if (llGround(ZERO_VECTOR)+50.0 < pos.z)
{
llSetBuoyancy(1.0);
}
else
{
llSetBuoyancy(0.0);
}

llTakeControls(gReqKeys, TRUE, TRUE);
}

changed(integer what)
{
if (what & CHANGED_REGION)
{
state landed;
}
}

on_rez(integer param)
{
llResetScript();
}

at_target(integer number, vector curPos, vector targPos)
{
llStopMoveToTarget();
}

control(key owner, integer held, integer change)
{
gotControlInput(held);

state default;
}

touch_start(integer num)
{
state disabled;
}

state_exit()
{
llStopMoveToTarget();
}
}


state landed
{
state_entry()
{
llStopMoveToTarget(); // just in case
llSetBuoyancy(0.0);
llSetColor(<0.5,0.5,0.25>, ALL_SIDES);
llSetTimerEvent(0.3);
}

on_rez(integer param)
{
llResetScript();
}

attach(key agent)
{
onAttach(agent);
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(gReqKeys, TRUE, TRUE);
}
}

touch_start(integer num)
{
state disabled;
}

timer()
{
gAgentInfo = llGetAgentInfo(gWearer);

if (gAgentInfo & AGENT_FLYING)
{
state default;
}
}
}

state disabled
{
state_entry()
{
llSetBuoyancy(0.0);
llStopMoveToTarget(); // just in case
llSetColor(<0,0,0>, ALL_SIDES);
}

attach(key agent)
{
onAttach(agent);
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(gReqKeys, TRUE, TRUE);
}
}

on_rez(integer param)
{
llResetScript();
}

touch_start(integer num)
{
state landed;
}
}

Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
09-05-2006 07:39
/15/4e/134594/1.html
_____________________
i've got nothing. ;)
Dr Tardis
Registered User
Join date: 3 Nov 2005
Posts: 426
09-14-2006 12:27
I can't figure out the bouyancy thing. I've tried experiments in the past, and nothing I've tried with bouyancy has actually affected the avatar's altitude. I'd much rather use this than setforce, since it's more controllable....
Boq Beauchamp
Registered User
Join date: 3 Oct 2006
Posts: 59
10-14-2006 10:46
Could someone explain what a HUD attachment point is and how to exactly use this script. (Dumb it up for someone who had to look up "HUD" in the wiki).
Dr Tardis
Registered User
Join date: 3 Nov 2005
Posts: 426
10-14-2006 11:52
If you've worn an object (by dragging it from your inventory window to your avatar), you've used an attachment. By default, an object attaches to your hand when you drag it to yourself (it used to attach to your head).

A HUD attachment doesn't show up for others to see, but instead is only visible inside your SL window.

this script would be used by installing it in an object. Here's the simple way:

1. Create an object. (Click build at the bottom of the screen to get started).
2. in the object's contents tab, click "New Script"
3. Copy the script from here to the clipboard and paste it in to your new script window.
4. right-click the object. you'll have to go through the sequence of menus until you find attach to HUD, then find a spot on the hud you like (doesn't matter where).
Xanshin Paz
Registered User
Join date: 24 Oct 2005
Posts: 17
how to use the flight assist script...
10-14-2006 12:13
Hi, Bog!

You probably already know that, in SL, the HUD is really the viewer you use to see what's going on- it's just the display you see every time you are in-world.

If you right click on any item in your inventory, or any object you've rezzed, one of the options you'll see is 'attach to HUD'. Click on that option and you'll see a number of choices: upper right corner, right edge, bottom right corner, bottom center (these may not be verbatim, but you get the idea....). These are the HUD attachment points. Choosing one will put the item you initially right clicked into that position in your viewer. A HUD attachment is only visible to you, unlike an object that is 'worn' which can be seen by people around you-like jewelry for example. ( just to confuse people, it seems recent versions of the client will only let you choose 'attach to HUD' the first time you attach an object there, after that, th e only option you'll see is 'wear'. Don't worry, the object will go right back to the HUD spot you first chose for it).

To use the script, first make a prim to hold it. Start large, because once you get it down to HUD scale, it could be hard to find! Try 1m x 1m x 0.1m ( that 10m dimension in the original post is a bit large....), and texture it as suggested.

Copy the script from the forum posting (you can paste it into Notepad if you want to build an offline collection of script examples!), then go into edit on the prim you created. Click on the 'Contents' tab, and find the button that says New Script. Click that, highlight the entire 'hello avatar!' code and select Paste from the Edit dropdown at the top of the viewer. Now the flight assist script is in your prim.

Edit the dimensions of your prim. A square 1 or 2 cm on a side, and 5mm thick should be fine. ( 0.01 x 0.01 x 0.005 m) (You can start larger , and edit it once you have it attached if you'd rather....experiment! ) Give it a descriptive name while you're at it, nothing is more frustrating than an inventory full of objects named Object.

Right click your new assist, choose 'attach to HUD' and pick your favorite spot. It will now go to the spot you chose. Edit the size and position as necessary to get it as you like it. Right click again and find 'Take Copy' to get a copy in your inventory.

If it's not already black, left click it to turn it off, and see how high you can fly. Left click it to turn it on, and try again! Welcome to the world of HUD mounted flight assist!

If you're real new to building, go to Dreams or The Ivory Tower Library of Prims for great basic to intermediate tutorials.
Vincent Nacon
Reseacher & Developer
Join date: 1 Mar 2006
Posts: 111
11-21-2006 13:05
Sorry, but there's an error with permission control, can't figure out what's wrong with it.

(didn't edit the script I put into my hud, just copy and paste from this post)
_____________________
A new horizon is coming... but what?
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-21-2006 15:04
replace getPermissions function.

This should make it work, the orig scripter thought that permissions accumulate, which they do not.
CODE

getPermissions()
{
if ((llGetPermissions() & gReqPerms) == gReqPerms)
{
llTakeControls(gReqKeys, TRUE, TRUE);
}
else
{
llRequestPermissions(gWearer, gReqPerms);
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Burke Prefect
Cafe Owner, Superhero
Join date: 29 Oct 2004
Posts: 2,785
11-21-2006 16:23
Can someone slap in some animation cues in there so I can add
a couple chunks for skydiving? (ie, detect falling)

Thanks.
_____________________
Morph Wollongong
Not a Copy
Join date: 19 May 2006
Posts: 13
bug fixes
12-01-2006 09:08
I did some more testing after Vincent Nacon reported problems with the script and there were basically two issues that surfaced.

One is that there are states that have missing attach()/run_time_permissions() events. The net effect is that if you attach the HUD when it is in "landed" state or in "disabled" state, it would not properly check/grant permissions and you would receive script errors.

I'll fix the original script to include the bug fixes including those from Strife Onizuka
Midori Mikazuki
Registered User
Join date: 20 Sep 2006
Posts: 78
12-01-2006 11:44
Do the bug fixes you're doing address the phenomenom of being stuck in the falling animation after a teleport? I'm suspecting that one might have to call llStopMoveToTarget after the TP, but I haven't had time to try to figure out how to detect the TP to call it, to see if it works.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-03-2006 19:57
WARN:: ( 75, 5): variable `hasPerms' declared but never used.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Morph Wollongong
Not a Copy
Join date: 19 May 2006
Posts: 13
removed superfluous line
12-12-2006 06:05
Removed the superfluous line Jesse noticed.
Morph Wollongong
Not a Copy
Join date: 19 May 2006
Posts: 13
Midori's falling animation behavior
12-14-2006 09:03
Seems to be fixed now
Midori Mikazuki
Registered User
Join date: 20 Sep 2006
Posts: 78
12-14-2006 10:17
From: Morph Wollongong
Seems to be fixed now

Hurray! Thank you.

-MM
Midori Mikazuki
Registered User
Join date: 20 Sep 2006
Posts: 78
12-22-2006 07:38
I've been racking my brains trying to figure out why this script works perfectly fine in the simple HUD object I made following the guide in the original posting, but does not work well at all if i stick it inside my Huddles EZ Animator. I think I finally figured it out: the EZ Animator is 31+ prims, making it too big for physics to work.

I feel silly now.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-22-2006 08:32
From: Midori Mikazuki
I've been racking my brains trying to figure out why this script works perfectly fine in the simple HUD object I made following the guide in the original posting, but does not work well at all if i stick it inside my Huddles EZ Animator. I think I finally figured it out: the EZ Animator is 31+ prims, making it too big for physics to work.

I feel silly now.

It needs to be in the root prim. I use a variation of it in a hud with no problems. As an attachment, the 31+ prims don't count. The attachment is not physical.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Midori Mikazuki
Registered User
Join date: 20 Sep 2006
Posts: 78
12-22-2006 09:03
From: Jesse Barnett
It needs to be in the root prim. I use a variation of it in a hud with no problems. As an attachment, the 31+ prims don't count. The attachment is not physical.


Are you sure the 31+ prims don't count in the attachment? I've tried the script in the root prim as well in child prims of the EZ Animator, and it just doesn't work. :( If it's not the prim count, I'm all confused again. Maybe the sheer number of items in the inventory of the EZ Animator (scripts, animations, objects-to-rez, sounds . . . . there's a lot in there)?

It works fine if I stick the script in the root prim of one of my smaller prim count "almost always worn" attachments, though. I just want to stick it in my "always, always worn" attachment. :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-22-2006 11:49
Hi Midori. I just double checked and put it in the root prim of a 50 prim object. attached it and it works fine.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
07-06-2007 12:06
For some reason I am having problem with the script moving too fast.
I would like it to allow me to fly at any hight but it does so so fast that I can't move around very well. I tried tweaking the gassist parameters but that didn't seem to work what am I doing wrong?
Morph Wollongong
Not a Copy
Join date: 19 May 2006
Posts: 13
gAssistParams
08-28-2007 13:27
Hi Dioxide,

Here's a quick overview of the gAssistParams list elements. Each vector is defined as:

< assistIncreaseFactor, maxAssist, maxHeight >

maxHeight is the max height that the given list element applies. If you are above that height, the script looks for the next element that applies. The list must be ordered by the maxHeight param (from least height to greatest).

The assistIncreaseFactor is a multiplier that is applied for each control input event received. So the the nearer to 1.0 this number is, the slower the "ramp up" for assist.

The maxAssist parameter is the maximum amount of push allowed when less than maxHeight.

So basically, if you like the rate that pushing ramps up, but don't like how fast you go, change the maxAssist parameter(s) to adjust them lower.

One last note, if maxHeight is -1, there is no upper bound for the param. This is used for the last item on the list and it applies as high as you have the patience to fly.
Little Gray
Registered User
Join date: 16 Oct 2006
Posts: 48
08-28-2007 16:00
where, precisely, is the script containing all the changes/bugfixes discussed in this thread to be found? Could someone post it please?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-28-2007 16:37
It's in the Scripting Library:

/15/4e/134594/1.html
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-28-2007 19:04
It is in the Script Library. Morph kept the script current with edits.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
08-28-2007 19:16
/15/4e/134594/1.html
1 2