Files

82 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2019-04-03 20:57:49 -05:00
// :SHOW:
2019-03-17 23:20:45 -05:00
// :CATEGORY:Scripting
2019-04-03 20:57:49 -05:00
// :NAME:Script Tests
2019-03-17 23:20:45 -05:00
// :AUTHOR:Justin Clark-Casey (justincc)
// :KEYWORDS:Opensim
2019-04-03 20:57:49 -05:00
// :CREATED:2019-04-04 20:49:51
// :EDITED:2019-04-04 19:49:51
// :ID:1124
// :NUM:1990
2019-03-17 23:20:45 -05:00
// :REV:1
// :WORLD:Opensim
// :DESCRIPTION:
// One of many tests for Opensim
// :CODE:
// This is a script designed to orbit its owner.
vector startPos;
vector curPos;
vector offset; // offset from Agent
integer iteration;
float rotationRate; // degrees of rotation per iteration
float sensorInterval; // seconds between sensor scan.
default
{
state_entry()
{
llOwnerSay( "Hello, Avatar! Touch to start orbiting." );
llSetStatus( 1, FALSE ); // turn Physics off.
offset = < 2, 2, 1 >;
iteration = 0;
rotationRate = .5;
sensorInterval = .3;
}
touch_start(integer total_number)
{
startPos = llGetPos();
curPos = startPos;
llSleep( .1 );
key id = llGetOwner();
llSensorRepeat( "", id, AGENT, 96, PI, sensorInterval );
}
sensor(integer total_number)
{
iteration++;
if( iteration > 300 )
{
llResetScript();
}
if( llDetectedOwner( 0 ) == llGetOwner() )
{ // the detected Agent is my owner.
vector position = llDetectedPos(0); // find Owner position.
// calculate next object position relative both to the Owner's
// position and the current time interval counter. That is,
// use the iteration counter to define a rotation, multiply
// the rotation by the constant offset to get a rotated offset
// vector, and add that rotated offset to the current position
// to defne the new position.
float degreeRotation = llRound( rotationRate * iteration ) % 360;
rotation Rotation =
llEuler2Rot( < 0, 0, degreeRotation * DEG_TO_RAD > );
vector rotatedOffset = offset * Rotation;
position += rotatedOffset;
// change the location of the object and save the current (rotated)
// offset for use during the next iteration.
llSetPos( position );
offset = rotatedOffset;
}
}
}