Difference between revisions of "Follower script"

From Second Life Wiki
Jump to: navigation, search
m
m (<lsl> tag to <source>)
 
(26 intermediate revisions by 9 users not shown)
Line 1: Line 1:
This script was extracted from the Batman Follower v1.2, but the following distance was changed from .3 m to .1 m.
+
This script is based on an extract from the Batman Follower v1.2.  It is very basic.  If you put it in an object, that object will keep moving toward a position ''offset'' from it's owner.
  
To set the following distance (distance between follower and followee), change the value denoted by # in '''llMoveToTarget(pos,#)'''. This script has it set at .1 m.
+
<source lang="lsl2">
 +
 
 +
vector offset = < -1, 0, 1>;  //1 meter behind and 1 meter above owner's center.
  
<pre>
 
 
default
 
default
 
{
 
{
 
     state_entry()
 
     state_entry()
 
     {
 
     {
        vector pos = llGetPos();
 
 
         llSetStatus(STATUS_PHYSICS, TRUE);
 
         llSetStatus(STATUS_PHYSICS, TRUE);
 +
        // Little pause to allow server to make potentially large linked object physical.
 
         llSleep(0.1);
 
         llSleep(0.1);
         llMoveToTarget(pos,0.1);
+
         // Look for owner within 20 metres in 360 degree arc every 1 seconds.
        key id = llGetOwner();
+
         llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
         llSensorRepeat("", "", AGENT, 96.0, PI, 0.4);
+
 
     }
 
     }
 
     sensor(integer total_number)
 
     sensor(integer total_number)
 +
    {  // Owner detected...
 +
        // Get position and rotation
 +
        vector pos  = llDetectedPos(0);
 +
        rotation rot = llDetectedRot(0);
 +
        // Offset back one metre in X and up one metre in Z based on world coordinates.
 +
        // use whatever offset you want.
 +
        vector worldOffset = offset;
 +
        // Offset relative to owner needs a quaternion.
 +
        vector avOffset = offset * rot;
 +
 +
        pos += avOffset;      // use the one you want, world or relative to AV.
 +
 +
        llMoveToTarget(pos,0.4);   
 +
    }
 +
}
 +
</source>
 +
<source lang="lsl2">
 +
//adding this script as a less laggy and more efficient way of doing the same as above
 +
//this is for havok4's new functions
 +
vector offset = < -1, 0, 1>;  //1 meter behind and 1 meter above owner's center.
 +
 +
default
 +
{
 +
    state_entry()
 
     {
 
     {
         vector pos = llDetectedPos(0);
+
        llSetStatus(STATUS_PHYSICS, TRUE);
         vector offset =<-1,0,1>;
+
        // Little pause to allow server to make potentially large linked object physical.
         pos+=offset;
+
        llSleep(0.1);
         llMoveToTarget(pos,0.1);    
+
        llSetTimerEvent(1.0);
 +
    }
 +
    timer()
 +
    {
 +
        list det = llGetObjectDetails(llGetOwner(),[OBJECT_POS,OBJECT_ROT]);//this will never fail less owner is not in the same sim
 +
        // Owner detected...
 +
        // Get position and rotation
 +
         vector pos   = llList2Vector(det,0);
 +
         rotation rot = (rotation)llList2String(det,1);
 +
        // Offset back one metre in X and up one metre in Z based on world coordinates.
 +
        // use whatever offset you want.
 +
        vector worldOffset = offset;
 +
        // Offset relative to owner needs a quaternion.
 +
        vector avOffset = offset * rot;
 +
 
 +
         pos += avOffset;       // use the one you want, world or relative to AV.
 +
 
 +
         llMoveToTarget(pos,0.4);
 
     }
 
     }
 
}
 
}
</pre>
+
</source>
 +
 
 +
 
 +
{{LSLC|Library|Follower}}
 +
{{LSLC|Examples|Follower}}

Latest revision as of 14:59, 24 January 2015

This script is based on an extract from the Batman Follower v1.2. It is very basic. If you put it in an object, that object will keep moving toward a position offset from it's owner.

vector offset = < -1, 0, 1>;  //1 meter behind and 1 meter above owner's center.
 
default
{
    state_entry()
    {
        llSetStatus(STATUS_PHYSICS, TRUE);
        // Little pause to allow server to make potentially large linked object physical.
        llSleep(0.1);
        // Look for owner within 20 metres in 360 degree arc every 1 seconds.
        llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
    }
    sensor(integer total_number)
    {   // Owner detected...
        // Get position and rotation
        vector pos   = llDetectedPos(0);
        rotation rot = llDetectedRot(0);
        // Offset back one metre in X and up one metre in Z based on world coordinates.
        // use whatever offset you want.
        vector worldOffset = offset;
        // Offset relative to owner needs a quaternion.
        vector avOffset = offset * rot;
 
        pos += avOffset;       // use the one you want, world or relative to AV.
 
        llMoveToTarget(pos,0.4);     
    }
}
//adding this script as a less laggy and more efficient way of doing the same as above
//this is for havok4's new functions
vector offset = < -1, 0, 1>;  //1 meter behind and 1 meter above owner's center.
 
default
{
    state_entry()
    {
        llSetStatus(STATUS_PHYSICS, TRUE);
        // Little pause to allow server to make potentially large linked object physical.
        llSleep(0.1);
        llSetTimerEvent(1.0);
    }
    timer()
    {
        list det = llGetObjectDetails(llGetOwner(),[OBJECT_POS,OBJECT_ROT]);//this will never fail less owner is not in the same sim
        // Owner detected...
        // Get position and rotation
        vector pos   = llList2Vector(det,0);
        rotation rot = (rotation)llList2String(det,1);
        // Offset back one metre in X and up one metre in Z based on world coordinates.
        // use whatever offset you want.
        vector worldOffset = offset;
        // Offset relative to owner needs a quaternion.
        vector avOffset = offset * rot;
 
        pos += avOffset;       // use the one you want, world or relative to AV.
 
        llMoveToTarget(pos,0.4);
    }
}