Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotational Problems

Gaynor Gritzi
Registered User
Join date: 16 Aug 2006
Posts: 48
06-26-2008 15:53
I'm still having problems with SL vectors and rotations.

I've got an object that when touched has to rez another object above it, but with the object's x direction (front) pointing at the av that clicked.

I thought this might work, but it doesn't and I've no idea why. Any suggestions? I'm baffled.


touch_start(integer total_number)
{
rotation angle=llRotBetween(llGetPos(),llDetectedPos(0));
llRezObject("object", llGetLocalPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, <0,0,angle.z,1.0>, 42);
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-26-2008 16:38
1. you find the angle between two global directions which is not what you want
2. the fourth argument for llRezObject must be a rotation not a vector
This is my humble tribute to a solution:
CODE
touch_start(integer total_number)
{
vector lookat = llDetectedPos(0)-llGetPos();
vector UP = < 0.0, 0.0, 1.0 >;
rotation faceav = llAxes2Rot(lookat, UP % lookat, UP);

llRezObject("object", llGetLocalPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, faceav, 42);
}
This will not work if the AV is directly above your object:-)
_____________________
From Studio Dora
Gaynor Gritzi
Registered User
Join date: 16 Aug 2006
Posts: 48
06-26-2008 17:42
Hmmm - just tried that and it rezzes at all kinds of angles.
Something still not right.
Thanks Dora
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-27-2008 01:08
I have added a line: 'lookat.z = 0.0;', but I am not sure it makes any difference.
CODE
touch_start(integer total_number)
{
vector lookat = llDetectedPos(0)-llGetPos();
lookat.z = 0.0;
vector UP = < 0.0, 0.0, 1.0 >;
rotation faceav = llAxes2Rot(lookat, UP % lookat, UP);

llRezObject("object", llGetLocalPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, faceav, 42);
}
1.Are you sure the detected avatar #0 is the one you think it is?
2.the rezzed object will have its FWD(x)-axis pointing to the #0 touching av
3.Do you have a good reason for using 'llGetLocalPos()' and not 'llGetPos()'? -the second argument for llRezObject is expected to have global coordinates.
_____________________
From Studio Dora
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-27-2008 02:15
I had to go in world and see for my self:-) I made one major change: All vectors are now unit vectors (magnitude == 1) and now it works!
CODE
default
{
touch_start(integer total_number)
{
vector lookat = llDetectedPos(0)-llGetPos();
lookat.z = 0.0;
lookat = llVecNorm( lookat );
vector UP = < 0.0, 0.0, 1.0 >;
rotation faceav = llAxes2Rot(lookat, UP % lookat, UP);

llRezObject("object", llGetPos() + <0.0, 0.0, 0.5>, ZERO_VECTOR, faceav, 42);
}
}
Happy scripting
_____________________
From Studio Dora
Gaynor Gritzi
Registered User
Join date: 16 Aug 2006
Posts: 48
06-27-2008 06:39
Just tried it and it works!
Thanks Dora, I would never have got there on my own.
I looked up llAxes2Rot on the wiki and didn't understand it at all.