
CODE
// Point Child At Target script by Cross Lament
//
// This script, placed in a child prim of an object, will cause
// the child prim to always point at the target location.
//
// This example uses a sensor to point the child prim's x-axis towards
// the nearest avatar.
vector targetaxis = < 1, 0, 0 > ; // The axis of the child prim you wish to point at the target object
// PointChildAtTarget( vector pos, vector axis ), point the child prim's axis towards region position pos.
PointChildAtTarget( vector pos, vector axis )
{
vector mypos = llGetPos() ; // The global position of the child prim
rotation rootrot = llGetRootRotation() ; // The rotation of the root prim
vector targetvector = llVecNorm( pos - mypos ) ; // The unit vector towards the target
// Find the global rotation between the desired axis and the target
// position, then unrotate this by the root prim's rotation
rotation targetrot = llRotBetween( axis, targetvector ) / rootrot ;
llSetLocalRot( targetrot ) ;
}
default
{
state_entry()
{
llSensorRepeat( "", NULL_KEY, AGENT, 10, PI, 1 ) ;
}
sensor( integer num )
{
PointChildAtTarget( llDetectedPos( 0 ), targetaxis ) ;
}
}