Difference between revisions of "Follower script"

From Second Life Wiki
Jump to: navigation, search
(added relative to owner)
Line 6: Line 6:
 
     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.
 
         // Little pause to allow server to make potentially large linked object physical.
 
         llSleep(0.1);
 
         llSleep(0.1);
        llMoveToTarget(pos,0.4);
 
 
         // Look for owner within 20 metres in 360 degree arc every 1 seconds.
 
         // Look for owner within 20 metres in 360 degree arc every 1 seconds.
 
         llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
 
         llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
 
     }
 
     }
 
     sensor(integer total_number)
 
     sensor(integer total_number)
     {
+
     {   // Owner detected...
         // Get position of detected owner
+
         // Get position and rotation
         vector pos = llDetectedPos(0);
+
         vector pos   = llDetectedPos(0);
 +
        rotation rot = llDetectedRot(0);
 
         // 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.
         // Offset relative to owner is possible but beyond the scope of this example.
+
         // use whatever offset you want.
         vector offset =<-1,0,1>;
+
         vector worldOffset = <-1, 0, 1>;
         pos+=offset;
+
        // Offset relative to owner needs a quaternion.
 +
        vector avOffset = worldOffset * rot;
 +
 
 +
         pos += avOffset;       // use the one you want, world or relative to AV.
 +
 
 
         llMoveToTarget(pos,0.4);     
 
         llMoveToTarget(pos,0.4);     
 
     }
 
     }

Revision as of 14:58, 23 September 2007

This script is based on an extract from the Batman Follower v1.2.

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 = <-1, 0, 1>;
        // Offset relative to owner needs a quaternion.
        vector avOffset = worldOffset * rot;

        pos += avOffset;       // use the one you want, world or relative to AV.

        llMoveToTarget(pos,0.4);     
    }
}