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? :D

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?"
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
04-26-2006 07:40
/54/a6/102700/1.html
_____________________
i've got nothing. ;)
Copper Surface
Wandering Carroteer
Join date: 6 Jul 2005
Posts: 157
04-27-2006 01:11
Actually, I find that very useful. Thank you ;) If it works for what I have in mind, I'll show it to you.