Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple rotation

Roland Gray
Registered User
Join date: 4 Oct 2006
Posts: 163
11-16-2009 05:21
I need to rotate an object arount the z axis only, to follow an avatar, and found this script which seemed to be exactly what I needed. BUT the object insists on rotating the x and y axes as well !! Can some kind person rescue me ?

vector AXIS_UP = <0,0,1>;
vector AXIS_LEFT = <0,1,0>;
vector AXIS_FWD = <1,0,0>;
rotation getRotToPointAxisAt(vector axis, vector target) {
return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos());
}


float strength = 1.0;
float damping = 0.250;

default {
state_entry() {

llSetStatus(STATUS_ROTATE_X, FALSE);
llSetStatus(STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_ROTATE_Z, TRUE);
llSensorRepeat("",NULL_KEY,AGENT,10,PI,1); //set the last three variables lower/higher to lessen lag

}

sensor(integer num_detected) {
vector target = llDetectedPos(0);

llRotLookAt(getRotToPointAxisAt(AXIS_FWD, target), strength, damping);
}
}
_____________________
TheMoreILearnTheLessIKnow
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
11-16-2009 06:10
Not enough time to really figure it out, but it seems to me that you have a vector variable named "axis" in there that never gets a value assigned. Could that be the problem?
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-16-2009 06:13
Try something like this:
CODE


key target;
default
{
state_entry()
{
target=llGetOwner();
llSetTimerEvent(0.5);
}

timer()
{
vector lookat = llList2Vector(llGetObjectDetails(target,[OBJECT_POS]),0);
vector me = llGetPos();
llRotLookAt(llRotBetween( < 1.0, 0.0, 0.0 >, llVecNorm( < lookat.x, lookat.y, me.z >-me )),1.0,0.1);
}
}

Not sure it's the best way, but I think it does what you want
Roland Gray
Registered User
Join date: 4 Oct 2006
Posts: 163
11-16-2009 07:03
TY Innula, worked perfectly (now i'll figure out how!!)
_____________________
TheMoreILearnTheLessIKnow
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-16-2009 09:10
From: Roland Gray
TY Innula, worked perfectly (now i'll figure out how!!)
Well,
CODE
    llRotLookAt(llRotBetween( < 1.0, 0.0, 0.0 >, llVecNorm( vecTarget-llGetPos())),1.0,0.1);
points your prim's x axis towards the centre of vecTarget, which is almost what you want. But if vecTarget and your prim are at different heights, then your prim is going to have to start swiveling on its y axis to look up or down, as well as turning round on its z axis to look left and right.

So I just told it to calculate a point at the same x and y coordinates as the target but at the same z coordinate as the prim, and to look at that. That way it never has to look up or down because, by definition, the target is at precisely the same altitude as the prim.