Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with Rotations and Positions?

Roburt Musketeer
Registered User
Join date: 31 Oct 2005
Posts: 17
12-18-2005 09:42
Okay, I'm a scripting novice, so please bear with me. :)

Without going into messy details, I am building an object that rezzes a second object in a very specific location relative to the first. I built and coded what I wanted without a problem using llRezObject and adjusting the position vector by using llGetPos() + <x,y,z>. All perfectly basic, standard stuff.

Now here is the problem. I want to be able to rotate the first object and still have it rez the second object in the correct spot relative to itself. I have no problem passing the first pobject's rotation to the second, but the problem is in the vector position. Since the first object has been rotated, the position also needs to be adjusted. Math used to be my strongsuit, but it's been a while since I took trig. Rather than puzzle it out on my own (I figure I can find the angle between the original position and the rotated position, and use sin and cosin to adjust the rez vector or something along those lines) I thought I'd ask in here and see if a) Anyone understands what I'm babbling about :) and b) If there's a simple, obvious way of doing this I just haven't stumbled across yet.

If not, I'll just gnaw at the problem until I cobble together some kind of fix to get what I want. :)
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
12-18-2005 09:53
This is amazingly simple... I'm no mathematician, so I can't explain this, but:

vector rezpos = llGetPos() + ( offsetvector * llGetRot() );

:)
_____________________
Roburt Musketeer
Registered User
Join date: 31 Oct 2005
Posts: 17
12-18-2005 14:26
Hmmmm.. I'm afraid that doesn't seem to work for me. I tried it in a object from the general library as well (The firework launcher to be specific) and tweaked it's code that way. When I rotate the launcher, the rocket still appears in the same position, not taking into acocunt the rotation of the luancher. So it's not just my messy code and rotations I think...

Edit: Oops! My apologies. I fiddled with it a bit, and I entered it slightly wrong. It works fine on the firework launcher. I'll have to mess with the code a bit more on my item then. Clearly it works in THEORY.. But I'm causing some other rotational effects, so maybe they're interfering... Trial and error time! :)
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
12-18-2005 14:37
Post your code!
_____________________
Roburt Musketeer
Registered User
Join date: 31 Oct 2005
Posts: 17
12-18-2005 14:54
Sure, here you go...

touch(integer Parameter)
{

rotation Cushion_Rot = llEuler2Rot(<0,90,0>*DEG_TO_RAD)*llGetRot();
llRezObject("Top Cushion" , llGetPos()+<0,.033,-.086> , ZERO_VECTOR , Cushion_Rot,0);

}

I have to rotate the second object (The cushion) 90-degrees for it to line up properly. The vector position then lines it up where it belongs. Th code above puts the cushion where it needs to be when the object is in it's initial, non rotated state. when I rotate it, the cushion appears with the correct rotation, but out of position.

Now, I adjusted the code as you suggested...

touch(integer Parameter)
{

rotation Cushion_Rot = llEuler2Rot(<0,90,0>*DEG_TO_RAD)*llGetRot();
llRezObject("Top Cushion" , llGetPos()+(<0,.033,-.086>*llGetRot()) , ZERO_VECTOR , Cushion_Rot,0);

}

But I end up in xactly the same spot both ways. I'm sure I'm just doing something stupid here, but rotations confuse the hell out of me. :(
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
12-18-2005 17:36
Well, it's working dandy fer me... so...

If it's in a child prim doing the rezzing, use llGetRootRotation() instead.

Otherwise... If that's not it, I'm stumped.
_____________________