## Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

# Point a child prim at a region-coordinate target

Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
04-25-2006 11:52
Basically, I wrote this just to figure out how. But hopefully someone will find the idea useful. Have I mentioned that I hate rotations, especially child rotations?

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 ) ;    }}`
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
The Librarian
Join date: 4 Nov 2002
Posts: 1,423