Point Child At Target
De DigiWiki.
This function, when called in a child prim of an object, will point the chosen axis of the child prim towards a target location specified in region-coordinates; a demonstration of how, if you wish to relate a child prim's rotation to the global axes, you need to unrotate your result by the root prim's rotation.
In this example, it is using a repeating sensor to point the child prim's x-axis at the nearest avatar.
// PointChildAtTarget - points child's 'axis' towards region-coordinate 'pos'. PointChildAtTarget( vector pos, vector axis ) { // The global position of the child prim. vector mypos = llGetPos() ; // The unit vector towards the target. vector targetvector = llVecNorm( pos - mypos ) ; // Find the rotation required to point the unrotated (ie. world) axis // towards the target, then unrotate this by the root prim's rotation. rotation targetrot = llRotBetween( axis, targetvector ) / llGetRootRotation() ; llSetLocalRot( targetrot ) ; } // The axis of the child prim you wish to point at the target object. vector desiredaxis = < 1, 0, 0 > ; default { state_entry() { llSensorRepeat( "", NULL_KEY, AGENT, 10, PI, 1 ) ; } sensor( integer num ) { PointChildAtTarget( llDetectedPos( 0 ), desiredaxis ) ; } }