User:Dale Innis/AutomaticWalking

From Second Life Wiki
< User:Dale Innis
Revision as of 10:20, 18 November 2012 by Dale Innis (talk | contribs) (Created page with "So I have my AvatarFollower script, which lets you automatically follow someone without having to keep track of them and push arrow keys and stuff. And one of the nice side-…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

So I have my AvatarFollower script, which lets you automatically follow someone without having to keep track of them and push arrow keys and stuff.

And one of the nice side-benefits of that is that while you're following someone, you don't have to hold down any arrow keys, so you can type in chatboxes and stuff (and for that matter like sort inventory) while you're walking along. Not to mention camming about so as to get good pictures of the two of you walking.

(Getting pictures of yourself walking is a hard thing to do in SL!)

So I thought it would also be good to have something similar where instead of following someone, you could just walk forward without having to hold down an arrow key, so you could also type and cam and take pictures and stuff while still walking.

Here's the current draft, more or less:

<lsl> // Tap fwd to walk forward, again or tap back to stop. // Side-arrows still turn you while walking forward // by Dale Innis

float RANGE = 2.0; // Meters away that we put the target float TAU = 1.0; // Make smaller for more rushed walking

integer tid = 0; integer walking = FALSE;

stopWalking() {

 walking = FALSE;
 llTargetRemove(tid);  
 llStopMoveToTarget();
 llOwnerSay("No longer autowalking.");

}

startWalking() {

 walking = TRUE;
 keepWalking();

}

keepWalking() {

 if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING) {
     stopWalking();
     return;
 }    
 llTargetRemove(tid);  
 llStopMoveToTarget();
 vector offset = <2*RANGE,0,0>*llGetRootRotation();
 vector targetPos = llGetPos() + offset;
 targetPos.z += llGround(offset) - llGround(ZERO_VECTOR); // helps only on ground
 llMoveToTarget(targetPos,TAU);
 tid = llTarget(targetPos,RANGE/2.0);  

}

default {

 state_entry() {
   if (llGetAttached()!=0)
       llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS);
 }
 
 attach(key id) {
     if (id==NULL_KEY) return;
 }
 
 run_time_permissions(integer perm) {
     llTakeControls(CONTROL_FWD|CONTROL_BACK|CONTROL_ROT_LEFT|CONTROL_ROT_RIGHT|CONTROL_UP,TRUE,TRUE);
 }
 
 control(key id,integer level,integer edge) {
     if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING) {
         stopWalking();
         return;
     }
     integer tap = edge & level;
     if (tap & CONTROL_FWD) {
         if (walking) {
             stopWalking();
         } else {
             startWalking();
         }
     }
     if (tap & CONTROL_BACK) {
         if (walking) stopWalking();
     }
     if (level & CONTROL_ROT_LEFT) {
         if (walking) keepWalking();
     }
     if (level & CONTROL_ROT_RIGHT) {
         if (walking) keepWalking();
     } 
 }
 on_rez(integer x) {
   llResetScript();   // Why not?
 }
 at_target(integer tnum,vector tpos,vector ourpos) {
   if (walking) keepWalking();
 }

} </lsl>