Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Advanced Pet 'Float and Follow'. Based off Logan Bauer's work.

Foolish Frost
Grand Technomancer
Join date: 7 Mar 2005
Posts: 1,433
04-18-2005 03:40
After looking at the basic pet script for making a following per, I decided to upgrade it for a slightly more organic movement model.

See here for the original script...

While I might sell the bots later, I felt it was a good idea to share the script upgrade publicliy. Only right since based off another's open-source work.

CODE
`////////////////////////////////////////////////////////////////////////// Open Shifting Float and Follow Script, by Foolish Frost.      //// From Open Basic Follower/Facing Script, by Logan Bauer. /////////////////////////////////////////////////////////////////////////// OFFSET is the position of your pet in relation to it's owner's position.// For example, in the default setting below, "vector offset =<-1,0,1>;"// I.E. (x,y,z), the -1 puts it 1m back behind owner, the 0 means don't have// it stay left or right, and 1 means have it stay 1m above it's owner.  // So, if you wanted the script to make it follow directly in front of you,// and to the left, then you would change it to "vector offset =<1,1,0>;"// llFrand(float max)vector offset =<-1.2,0,1>;vector currentoffset =<0,0,0>; float xshift =.2; //How far it roams forward and back.float yshift =1.25; //How wide it roams left to right.float bob =2; //multiplyer of the BobCycle listed below.float shifttime =5; //average time it takes to shift to another XY position.integer timeset=0; //Is the timer running?float currentxshift =0; //current X shift positionfloat currentyshift =0; //current Y shift positionfloat currentyfacing =0; //currentyfacing storageinteger currentbob; //current state of the BobCyclefloat bobbing =0; //bob storagelist BobCycle = [0.0, 0.08, 0.12, 0.14, 0.15, 0.14, 0.12, 0.08, 0.0, -0.08, -0.12, -0.14, -0.15, -0.14, -0.12, -0.08];startup(){        vector pos = llGetPos();        llSetStatus(STATUS_ROTATE_Z,TRUE);        llSetStatus(STATUS_PHYSICS, TRUE);        key id = llGetOwner();        llSensorRemove();        llSensorRepeat("",llGetOwner(),AGENT,200,2*PI,.5);}default{        state_entry()    {        startup();           }    on_rez(integer start_param)    {        startup();    }    sensor(integer total_number)     {        vector pos = llDetectedPos(0);        bobbing = llList2Float(BobCycle, currentbob)*bob;                llSetTimerEvent(llFrand(shifttime));        currentoffset = <currentxshift, currentyshift, bobbing>;        llMoveToTarget(pos+(offset+currentoffset)*llDetectedRot(0),.3);        if (currentyshift>=0)        {            currentyfacing = currentyshift;        } else {            currentyfacing = currentyshift*-1;        }                llLookAt(pos+<0,0+(currentyfacing*.33),1+bobbing>, 1 , 2);                 currentbob = currentbob +1;        if (currentbob == 16)        {            currentbob = 0;        }                if(timeset==0)        {            timeset = 1;            llSetTimerEvent(((llFrand(shifttime)+llFrand(shifttime)+llFrand(shifttime))/3)*2);        }                    }            timer()    {        timeset = 0;        currentyshift = llFrand(yshift*2)-yshift;        currentxshift = llFrand(xshift*2)-xshift;    }}`
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Post:
04-21-2005 22:31
/15/a4/43244/1.html
_____________________
i've got nothing.
Chris Wilde
Custom User Title
Join date: 21 Jul 2004
Posts: 768
04-23-2005 08:24
Anyway to make it follow an object based on the objects name and not UID?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-23-2005 09:58
Yes, you put the name in the relevant part of the sensor code, not the key in that part. Try looking at the wiki for sensors.
Chris Wilde
Custom User Title
Join date: 21 Jul 2004
Posts: 768
04-23-2005 12:36
Thanks! I got it to follow my vehicle when my vehicle is in use. Not sure if I can get it to follow when not in use but thats something I can live with.
Foolish Frost
Grand Technomancer
Join date: 7 Mar 2005
Posts: 1,433
04-23-2005 16:36
Glad it's useful. Just remember, you can change the 'drift' and 'bob' sections of the script so it can cover differing areas, or set them to zero to have them stay in perfect position...
Blain Candour
Registered User
Join date: 17 Jun 2005
Posts: 83
confused
06-22-2005 01:59
The old basic script works fine for me but with this one my pet just plops to the ground and lays there. Am I the onyl one who this does not work for?