Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Relative position problem.

Dudskie Aabye
Registered User
Join date: 13 Sep 2007
Posts: 8
09-13-2007 04:32
Hi... I have this problem, I have create a script that deals with movements of an object. Below is the full details of an object and a prim.

Object 1<===>Prim <===>Object2


The above three (Object1, Prim and Object2 is not link to each other).

Now, Object1 has the script below:

vector startPos;
float x_dist = 0.5;
float y_dist = 0.0;
float z_dist = 0.0;



default
{
state_entry()
{
startPos = llGetPos();

llListen(0, "", "", "moving close" );
llListen(0, "", "", "moving open";);
}
on_rez(integer num)
{
llResetScript();
}

listen(integer number, string name, key id, string message)
{
if(message == "moving open";)
{
vector increment;
if (increment = <x_dist, y_dist, z_dist>;)
{
vector newPos = startPos - increment;
llSetPos(newPos);
}

vector newPos;

newPos = llGetPos();

vector y_decrement = <x_dist, 0.9, z_dist>;
vector yrepoPos = startPos - y_decrement;
llSetPos(yrepoPos);






}

if(message == "moving close";)
{

state close;
}
}

}

state close
{
state_entry()
{
startPos = llGetPos();


vector decrement = <x_dist, y_dist, z_dist>;
vector repoPos = startPos + decrement;
llSetPos(repoPos);


repoPos = llGetPos();

vector y_decrement = <x_dist, 0.9, z_dist>;
vector yrepoPos = startPos + y_decrement;
llSetPos(yrepoPos);

llResetScript();

}


}


Object2 has the script below:



vector startPos;
float x_dist = 0.5;
float y_dist = 0.0;
float z_dist = 0.0;



default
{
state_entry()
{
startPos = llGetPos();

llListen(0, "", "", "moving close" );
llListen(0, "", "", "moving open";);
}
on_rez(integer num)
{
llResetScript();
}

listen(integer number, string name, key id, string message)
{
if(message == "moving open";)
{
vector increment;
if (increment = <x_dist, y_dist, z_dist>;)
{
vector newPos = startPos + increment;
llSetPos(newPos);
}

vector newPos;

newPos = llGetPos();

vector y_decrement = <x_dist, -0.9, z_dist>;
vector yrepoPos = startPos + y_decrement;
llSetPos(yrepoPos);






}

if(message == "moving close";)
{

state close;
}
}

}

state close
{
state_entry()
{
startPos = llGetPos();


vector decrement = <x_dist, y_dist, z_dist>;
vector repoPos = startPos - decrement;
llSetPos(repoPos);


repoPos = llGetPos();

vector y_decrement = <x_dist, -0.9, z_dist>;
vector yrepoPos = startPos - y_decrement;
llSetPos(yrepoPos);

llResetScript();

}


}


Now, the problem is, when I rotate the whole stuff and then run the script the scripted object will not run relative to the position. How can I fix that? Thanks in advance...
Jen Creeley
Registered User
Join date: 21 Oct 2006
Posts: 5
09-13-2007 08:07
I cant follow exactly what your doing, but for vectors relative to rotation multiply the vector by llGetRot()