Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Alternative to llLookAt using llSetRot

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-20-2005 09:24
For some applications llLookAt doesn't function like it should, for example a HUD attachment that's supposed to point at a specific spot, or if for some strange reason you wanted your prim to look along a unit vector. What I have done here is reconstructed the llLookAt function using llSetRot. I used global coordinates so that if it's a fixed point, it will work across sim borders. the vector lookat is where the object will point to (in global coordinates). the prim points along it's Z axis, but you could easily change it so that it pointed along it's x or y axis by changing the <0,0,1> vector in the llGetRotBetween command to the appropriate unit vector.

*how it works*
very simple really, it takes your position (or the prims) and the coordinates of where it's supposed to be looking at and creates a vector between them. then it uses the llGetRotBetween to get a rotatation between the z axis and where you want to look at and then applies that rotation to the llSetRot command.

Of note is the llSetRot command itself; there is a divisor in there. this is because I'm assuming it's an attachment and it corrects for the avatar's orientation. if this is going to be put in a object that's not attached to an avatar, then the line should be :
if you leave it "as is" in an unattached prim your pointer will dance :)


vector lookat = <0,0,0>; //this is where the item will look at. remember to add +llGetRegionCorner() to the coordinates if they're taken from a sensor.

default {

state_entry() {

llSetTimerEvent(.01);//because llSetRot is not "autoupdating" like llLookAt(), we need to constantly update where it's looking to.


vector gposition = ( llGetRegionCorner()+llGetPos() ); //global position of the prim.
vector target = (lookat - gposition); // A vector to rotate along. "lookat" is where it's going to look at in global coordinates.
rotation rotvec = llRotBetween(<0,0,1>,llVecNorm(target)); //the rotation quaternion to rotate our object from pointing "up" towards the vector pointing at the waypoint

Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
11-20-2005 22:56
i've got nothing. ;)