Skip to content

Instantly share code, notes, and snippets.

@Martin-Pitt
Last active August 28, 2024 04:34
Show Gist options
  • Save Martin-Pitt/fd40476d1ef086d6051b273e6ac972d1 to your computer and use it in GitHub Desktop.
Save Martin-Pitt/fd40476d1ef086d6051b273e6ac972d1 to your computer and use it in GitHub Desktop.
key object;
default
{
state_entry()
{
llSetScale(llGetAgentSize(llGetOwner()));
llSensorRepeat("Target", "", ACTIVE|PASSIVE, 96.0, TWO_PI, 1.0);
}
sensor(integer detected)
{
llSetText("", <1,1,1>, 1);
object = llDetectedKey(0);
llSetTimerEvent(0.25);
llSensorRemove();
}
no_sensor()
{
llSetText("Unable to find \"Target\" prim", <1,1,1>, 1);
}
timer()
{
list objectDetails = llGetObjectDetails(object, [OBJECT_POS, OBJECT_ROT, OBJECT_SCALE]);
if(objectDetails == []) return;
vector objectPos = llList2Vector(objectDetails, 0);
rotation objectRot = llList2Rot(objectDetails, 1);
vector objectScale = llList2Vector(objectDetails, 2);
vector agentSize = llGetScale(); // Use self as reference
list corners = [
< objectScale.x, objectScale.y, objectScale.z>,
<-objectScale.x, objectScale.y, objectScale.z>,
< objectScale.x,-objectScale.y, objectScale.z>,
<-objectScale.x,-objectScale.y, objectScale.z>,
< objectScale.x, objectScale.y,-objectScale.z>,
<-objectScale.x, objectScale.y,-objectScale.z>,
< objectScale.x,-objectScale.y,-objectScale.z>,
<-objectScale.x,-objectScale.y,-objectScale.z>
];
list heights;
integer iterator = llGetListLength(corners);
while(iterator --> 0)
{
vector location = llList2Vector(corners, iterator) * objectRot;
heights += [location.z];
}
float max = llListStatistics(LIST_STAT_MAX, heights);
vector position = objectPos + <0, 0, max/2> + <0, 0, agentSize.z/2>;
llSetRegionPos(position);
}
}
default
{
state_entry()
{
llSetScale(<1, 2, 3>);
llSetTimerEvent(0.5);
}
timer()
{
rotation randomRotation = llEuler2Rot(<llFrand(TWO_PI) - PI, llFrand(TWO_PI) - PI, llFrand(TWO_PI) - PI>);
llSetRot(randomRotation);
}
}
@Martin-Pitt
Copy link
Author

Martin-Pitt commented Aug 28, 2024

Drop Test Object.lsl into a cube named Target and then create a new cube for the Follow Above Object.lsl script.

The follower will always sit right above the axis aligned bounding box of the target object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment