Jump to content
  • 0

Script to rez object at the correct angle?


Aerikah Xeltentat
 Share

You are about to reply to a thread that has been inactive for 2926 days.

Please take a moment to consider if this thread is worth bumping.

Question

I'm trying to build a rezzer that will rez items (vehicles) at a certain location & angle relative to the rezzer. The script I have works except that the items rez parallel to the rezzer & I need them to face away from the rezzer at a 45 degree angle.
I've been googling for hours trying to figure out how to edit my script & haven't been able to figure it out. My scripting abilities only consist of tweaking variables in scripts that I already have, but if this script even contains the variables I need to tweak I can't find them.
Could someone please help me fix my script so the rotation is right?

 

This is the script I have:

list MENU1 = [];
list MENU2 = [];
integer listener;
integer MENU_CHANNEL = 1000;
 
 
Dialog(key id, list menu)
{
    llListenRemove(listener);
    listener = llListen(MENU_CHANNEL, "", NULL_KEY, "");
    llDialog(id, "Select one object below: ", menu, MENU_CHANNEL);
}
 
default
{
    on_rez(integer num)
    {
        llResetScript();
    }
 
    touch_start(integer total_number)
    {
        integer i = 0;
        MENU1 = [];
        MENU2 = [];
        integer c = llGetInventoryNumber(INVENTORY_OBJECT);
        if (c <= 12)
        {
            for (; i < c; ++i)
                MENU1 += llGetInventoryName(INVENTORY_OBJECT, i);
        }
        else
        {        
            for (; i < 11; ++i)
                MENU1 += llGetInventoryName(INVENTORY_OBJECT, i);
            if(c > 22)
                c = 22;
            for (; i < c; ++i)
                MENU2 += llGetInventoryName(INVENTORY_OBJECT, i); 
            MENU1 += ">>";
            MENU2 += "<<";                          
        }
        Dialog(llDetectedKey(0), MENU1);
    }
 
    listen(integer channel, string name, key id, string message) 
    {
        if (channel == MENU_CHANNEL)
        {
            llListenRemove(listener);  
            if (message == ">>")
            {
                Dialog(id, MENU2);
            }
            else if (message == "<<")
            {
                Dialog(id, MENU1);
            }        
            else                    
            {
                // todo add offsets so box sites perfect on rezzer 
                llRezAtRoot(message, llGetPos() + <2.9,2.8,0.15>, ZERO_VECTOR, llGetRot(), 0);
            }      
        }
    }  
}
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi Aerikah,

Here's how llRezAtRoot() works...

http://wiki.secondlife.com/wiki/LlRezAtRoot

Look at the llRezAtRoot() call in your script. You'll see that it rezzes your vehicle at an offset from the script position...

llGetPos() + <2.9,2.8,0.15>

with no velocity...

ZERO_VECTOR

and the same orientation as the script's prim...

llGetRot()

Look at the example at the bottom of the wiki page, you'll see how to specify a rotation with respect to the script's prim. Rotations in SL are odd things, expressed as "quaternions" using radians rather than degrees. Rather than glaze your eyes over with an explanation of those, I'll direct you to...

http://wiki.secondlife.com/wiki/LlEuler2Rot

and...

http://wiki.secondlife.com/wiki/DEG_TO_RAD

llEuler2Rot() converts an X/Y/Z rotation into something llRezAtRoot() can use, and the constant DEG_TO_RAD scales tiny degrees into larger radians. You want to rotate your vehicle 45 degrees on the Z (vertical) axis, which is expressed as...

llEuler2Rot(<0,0,45>*DEG_TO_RAD)

And you want to add that rotation to the script's rotation, which is done by... multiplying! (those wacky quaternions!).

So here's the rotation argument you want in your script (I think) in place of the llGetRot() that's already there...

llGetRot() * llEuler2Rot(<0,0,45>*DEG_TO_RAD)

If I've made an error here, I hope Rolig will spot and fix it.

Good luck!

  • Like 1
Link to comment
Share on other sites

  • 0

I missed seeing this thread somehow, but Maddy got most of it spot on.  The only part you probably still need to think about is the very last step.  In the context of your example, adding an extra 45 degree rotation around Z is a local rotation ( that is, a rotation around the object's own Z axis, not the global Z axis.)  To do a local rotation you need to write it with the final rotation on the left and the object's rotation relative to the global axis on the right.  So, it should be

 llEuler2Rot(<0,0,45>*DEG_TO_RAD) * llGetRot()

And your complete movement should be described by

llGetPos() + <2.9,2.8,0.15> * llEuler2Rot(<0,0,45>*DEG_TO_RAD) * llGetRot()

The best way to think about this is to read the order of operations from left to right (or, if it makes more sense, by shifting your point of view from the object to positions that are farther and farther away):

1. Start where I am ( llGetPos() )

2. Then move me by an offset of <2.9,2.8,0.15> meters

3. Then rotate me 45 degrees around my own Z axis

4. Then correct the final position by accounting for my initial global rotation ( llGetRot() )

This seems confusing at first because we are accustomed to multiplying integers and fractions, where the operation is commutative.  That is, A * B = B * A .  The order doesn't make any difference.  Rotations and vectors don't work that way.  They are non-commutative, so A * B is not the same as B * A.  The rotation or vector on the left is operated on by the one on the right.

As it turns out, your specific example is probably a trivial case in which it the calculated local rotation is exactly the same as the global rotation, so it doesn't make any practical difference whether you write the statement as Maddy suggested or the other way around.  That's because unless you have done something to mess it up, your object's local Z axis is probably pointing the same direction as the global Z axis.  However, if your object had been tilted to start, you'd get the wrong answer if you arranged the rotations backwards.

If you want to get truly confused, study http://wiki.secondlife.com/wiki/Rotation . It's heavy going, but once you have it crammed into your head, you'll be amazed at how logical it all is.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2926 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...