Jump to content

Avatar rotation parameters to a fixed position following a random teleport


InBeTwine Exonar
 Share

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

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

Recommended Posts

Hi folks,

Now that I have a random teleporter working (thanks to the forum), I would like to add rotation parameters.  The way that the script is being used is to randomly teleport the avatar to one of four locations in a water maze pool, but each time the avatar teleports I would like it to always face an object at xy coordinate (33, 39). I am guessing that my rotation scripting relative to the random target selected will need to be inserted at the target line, but not sure how to properly write it. Any help would be greatly appreciated.

 

string fltText = "Random Teleporter"; //label that floats above Teleport

list a = [

<33.423, 56.900, 20>,

<33.423, 22.500, 20>,

<50.700, 39.924, 20>,

<16.623, 39.924, 20>
]; // list of nearby target

integer total;         //so you can add or subtract things to the list without changing the script

integer chosen;     //you choose an random float that is less  then the total, then round down  - this will give you a number that is between 0 and 1 less then the total number of entries in the line.

vector targetPos;


reset()
{
    vector target;
    chosen = llFloor(llFrand(llGetListLength(a)));
    targetPos = llList2Vector(a, chosen);
    target = (targetPos- llGetPos()) * (ZERO_ROTATION / llGetRot()); //I am guessing that here is where I should be writing code to orient the avatar to xy coordinate (33, 39)
    llSitTarget(target, ZERO_ROTATION);
    llSetSitText("Teleport");
    llSetText(fltText, <1,1,1>, 1);

}
default
{
    state_entry()
    {
        total = llGetListLength(a);
        reset();
    }
    
    on_rez(integer startup_param)
    {
        reset();
    }
    
    changed(integer change)
    {
        llSleep(0.15);
        llUnSit(llAvatarOnSitTarget());
        reset();
    }    
}

 

Link to comment
Share on other sites

If you change the rotation where you are proposing to do it, you will end up in a different spot.  The rotation in that line is correcting the target position for any rotation in your teleporter.  What you want to do is change your orientation on the teleporter itself.  To do that, change the sit target.  You can do that easily in this case because the sit target is defined before anyone sits on the teleporter.  So, instead of llSitTarget(target,ZERO_ROTATION), you want llSitTarget (target, new_rotation).  The real trick is figuring out what that new_rotation should be. One way is to do it empirically.  You only have four potential targets, so set up the device by visiting each location in turn, then figuring out how much you need to rotate in order to face (33,89,z).  Another way is to calculate the rotation.  I think this ought to work (untested, but it looks right) ...

rotation new_rotation = llRotBetween( <1.0,0.0,0.0>, llVecNorm( <33.0,89.0,target.z> - target ) );

You may need to multiply that by llGetRot(), but I think not.  I can't get in world to be sure.

Link to comment
Share on other sites

Hi Rolig,

Looks like it hangs right after llRotBetween in this new line rotation new_rotation = llRotBetween

string fltText = "Random Teleporter for Visible Trial"; //label that floats above Teleportlist a = [<33.423, 56.900, 20>,<33.423, 22.500, 20>,<50.700, 39.924, 20>,<16.623, 39.924, 20>]; // list of nearby targetinteger total;         //so you can add or subtract things to the list without changing the scriptinteger chosen;     //you choose an random float that is less  then the total, then round down  - this will give you a number that is between 0 and 1 less then the total number of entries in the line.vector targetPos;rotation new_rotation = llRotBetween( <1.0,0.0,0.0>, llVecNorm( <33.0,89.0,target.z> - target ) );//Script compile hangs here after llRotBetweenreset(){    vector target;    chosen = llFloor(llFrand(llGetListLength(a)));    targetPos = llList2Vector(a, chosen);    target = (targetPos- llGetPos()) * (ZERO_ROTATION / llGetRot());    llSitTarget(target, new_rotation);     llSetSitText("Teleport");    llSetText(fltText, <1,1,1>, 1);}default{    state_entry()    {        total = llGetListLength(a);        reset();    }        on_rez(integer startup_param)    {        reset();    }        changed(integer change)    {        llSleep(0.15);        llUnSit(llAvatarOnSitTarget());        reset();    }    }

 

( <1.0,0.0,0.0>, llVecNorm( <33.0,89.0,target.z> - target ) );

Link to comment
Share on other sites

That's because you can't calculate values of variables unless you are in an event or a user-defined function.  You are trying to calculate the value as you declare the variable new_rotation. That variable doesn't need to be global, because you are only using it in one place.  What you want instead is ....

reset(){    vector target;    chosen = llFloor(llFrand(llGetListLength(a)));    targetPos = llList2Vector(a, chosen);    target = (targetPos- llGetPos()) * (ZERO_ROTATION / llGetRot());    rotation new_rotation = llRotBetween( <1.0,0.0,0.0>, llVecNorm(<33.0,89.0,target.z> - target ) ); //Here, see?    llSitTarget(target, new_rotation);     llSetSitText("Teleport");    llSetText(fltText, <1,1,1>, 1);}

 That ought to work.

ETA:  I'm still not sure whether you'll need to multiply new_rotation by llGetRot(), and I can't get in world to test it myself.

Link to comment
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...