Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Plainer non-physical lookat functionality script – Example?

Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
01-24-2009 04:56
How do you make a prim turn on a single axis like a arrow pointer on a flat plane? I found this forum post and tried the scripts, but it all works the same as the lllookat function. I want it to be a none physical prim plainer prim that can point point in the direction of a person, like a compass. Is there an easy way to do this?

/54/0b/297621/1.html
Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
01-24-2009 05:48
I played with the script trial and error and this seems to work. I have no idea why or how. If anyone feels like telling my why this works or if this can be simplified I would appreciate it.


CODE


//cache this global variable to not have to compute it again and again
rotation rot90OnZ;
// Strength and damping are values used to control how llRotLookAt and llLookAt move, these values are tunable.
float strength = 1.0;
float damping = 1.0;

default
{
state_entry()
{
//first save a rotation we'll be usign later:
rot90OnZ = llEuler2Rot(<0,0,PI_BY_TWO>);
llSay(0, "Ready For Operation");
llSensorRepeat( "", "",AGENT,96, PI,0.2);
}

sensor(integer sense)
{
vector target = llDetectedPos(0); // A vector to look at.
target = target - llGetPos(); //make it local
//the direction of the target, normalized:
vector wantedFwd = llVecNorm(target);
//taking the horizontal component of the target vector,
//and rotating it 90 degrees around Z to get a horizontal
//vector pointing pependicular to the target:
vector wantedLeft=llVecNorm(<0.0, 0.0, 0.1>);
//create a global rotation that would satisfy these 2 vectors
rotation rot = llAxes2Rot(wantedFwd, wantedLeft, wantedFwd % wantedLeft);
//make the object look at the rotation:
llRotLookAt(<0.0,0.0,rot.z,rot.s>, strength, damping);
}
}

Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
01-24-2009 16:55
From: Dragon Muir
How do you make a prim turn on a single axis like a arrow pointer on a flat plane? I found this forum post and tried the scripts, but it all works the same as the lllookat function. I want it to be a none physical prim plainer prim that can point point in the direction of a person, like a compass. Is there an easy way to do this?

yes:
CODE

default
{
state_entry()
{
vector V = < persons coordinates >;
V.z = 0.0; // persons level set zero
vector W = llGetPos();
W.z = 0.0; // same level as person
llSetRot( llRotBetween( < 1.0, 0.0, 0.0 >, llVecNorm(V-W))); // point objects X-axis towards the person
}
}
_____________________
From Studio Dora
Fire Centaur
Creator
Join date: 2 Nov 2006
Posts: 149
Rotation Question
10-27-2009 02:28
why does this script still rotate on Y and X if I add

llSetStatus(STATUS_ROTATE_X, FALSE);
llSetStatus(STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_ROTATE_Z, TRUE);

????
_____________________
Second Life to your Facebook Profile!
http://www.facebook.com/p.php?api_key=00b8153d7f12a4c7228b6c927fb2c537
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
10-27-2009 04:15
I guess the object must be physical for the status flags to work
_____________________
From Studio Dora