Difference between revisions of "Follower script"

From Second Life Wiki
Jump to: navigation, search
(added relative to owner)
(cleaned up, added Example category)
Line 1: Line 1:
This script is based on an extract from the Batman Follower v1.2.
+
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.
  
 
<pre>
 
<pre>
 
default
 
default
 +
 +
vector offset = < -1, 0, 1>;  //1 meter behind and 1 meter above owner's center.
 
{
 
{
 
     state_entry()
 
     state_entry()
Line 19: Line 21:
 
         // Offset back one metre in X and up one metre in Z based on world coordinates.
 
         // Offset back one metre in X and up one metre in Z based on world coordinates.
 
         // use whatever offset you want.
 
         // use whatever offset you want.
         vector worldOffset = <-1, 0, 1>;
+
         vector worldOffset = offset;
 
         // Offset relative to owner needs a quaternion.
 
         // Offset relative to owner needs a quaternion.
         vector avOffset = worldOffset * rot;
+
         vector avOffset = offset * rot;
  
 
         pos += avOffset;      // use the one you want, world or relative to AV.
 
         pos += avOffset;      // use the one you want, world or relative to AV.
Line 30: Line 32:
 
</pre>
 
</pre>
  
{{LSLC|Library|Follower}}
+
{{LSLC|Library|Follower}} {{LSLC|Examples}}

Revision as of 15:08, 23 September 2007

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.

default

vector offset = < -1, 0, 1>;  //1 meter behind and 1 meter above owner's center.
{
    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);     
    }
}