lookat vector with OsTeleportAgent & OsTeleportOwner

I’ve noticed various advice about how to point the agent (i.e. your avatar) after teleporting using a script in OpenSim. This is done with OsTeleportAgent and OsTeleportOwner. Unlike llMapDestination, the lookat vector is actually implemented, which is rather pleasing. However, there is no documentation on how to use it, at the time of writing.

There are no clear instructions anywhere on the Web, and some of the advice I have seen appears to be wrong. For instance, one person suggested putting a prim on the ground in the direction you want your avatar to look and then using its coordinates. I can confirm that this does not work except for in one case (rather like the stopped clock being correct once a day). It is not a Euler vector in radians corresponding to a rotation, so please don’t waste your time trying stuff like llRot2Euler(rot) and so on. This will simply confuse you for longer than is necessary.

It appears that these work if you are teleporting within a region, but the lookat vector simply fails if you are teleporting between regions. In inter-region teleports, I am always pointing due East, or slightly turned to the SE if I am too near to non-phantom objects. It just doesn’t work, whatever the numbers are. However, intra-region teleports appear to work as follows:

Teleporting within the same region

In fact, the actual numbers in the vector don’t seem to matter if they are high enough, and only X & Y work at all because your avatar will not be pointing upwards. Quite simply, due North is <0,10,0>, due South is <0,-10,0>, due East is <10,0,0>, due West is <-10,0,0> and so on. The figure 10 is arbitrary. I’ve found it works with any positive number. Provided that X and Y are equal, this would mean that NE is <10,10,0>, SE is <10,-10,0>, SW is <-10,-10,0> and NW is <-10,10,0>. You can work out the minor points of the compass yourself from those, I hope.

So, to summarise, the agent is pointing in the direction of the relative axes, not rotated around them as with other vectors.

Another very weird aspect of OsTeleportAgent and OsTeleportOwner is that, after saving the script and teleporting, you will notice that it always fails the first time but succeeds on every subsequent attempt. This seems to be a very minor, completely reproducible bug. This confused me for a long time, leading me to much unnecessary extra fiddling with my scripts before I realised how it actually works.

Teleporting to other regions

Apparently, any lookat vector will currently give the same result. I am currently using the OpenSim 0.7.5 release version.

Further notes

I used the following syntax (the second variant in the documentation):

void osTeleportAgent(string agent, string regionName, vector position, vector lookat)

void osTeleportOwner(string regionName, vector position, vector lookat)

I have not tested the other two variants:

void osTeleportAgent(string agent, integer regionX, integer regionY, vector position, vector lookat)

void osTeleportOwner(integer regionX, integer regionY, vector position, vector lookat)

void osTeleportAgent(string agent, vector position, vector lookat)

void osTeleportOwner(vector position, vector lookat)

The former pair just show an alternative way of describing a region, using its coordinates rather than its name. The variant that I have used is the best for hypergrid even though the documentation wrongly says it can only be used for a local grid. The code examples prove otherwise. Obviously, the last variant is only useful within the current region. There is no reason to think – although I have not tested this – that the lookat vector behaves any differently in inter-region teleports based on how you specify which region is your destination. However, just as a last caveat, I should add that I did this testing within a local grid, as I have not yet had time to wait for the often slow hypergrid teleports in order to test it on hypergrid fully.

Please let me know if you’ve found any relevant bug reports or documentation that I’ve missed 🙂

It’s a real shame that the lookat vectors only work within the current region, as they are very useful.

Advertisements
Leave a comment

4 Comments

  1. Note that this has been an issue since before 2009 according to the Mantis bug report below, but there seems to be no fuller description available (?) than the above post.

    http://opensimulator.org/mantis/view.php?id=3631

    Reply
  2. Crystal

     /  August 10, 2014

    I was looking for the math to calculate the lookat vector, and all I found was a bunch of people that don’t know. Then I realized it is probably just a standard rotation vector around the Z axis, which my tests with osTeleportAgent seem to have confirmed. So, I wanted to share with anyone else who stumbles across this blog a simple formula to convert an angle into a lookat vector.

    The first thing to know is that due East is 0 degrees, North is 90 degrees, West is 180 degrees, and South is 270 degrees. Given that, if I want to face North, I would use the vector . The way to calculate that in an LSL script would look like this:

    float angle = 90.0;
    vector lookat = <llCos(angle * DEG_TO_RAD),llSin(angle * DEG_TO_RAD),0.0>;

    The nice thing about the math is that any equivalent angle yields the same vector, such as -270.0 or 450.0 (which are both the same as 90.0).

    Reply
    • Crystal

       /  August 10, 2014

      I think my math got stripped out because of angle brackets…
      vector lookat = <llCos(angle * DEG_TO_RAD),llSin(angle * DEG_TO_RAD),0.0>;

      Reply
      • I’ve edited both your comments by using &lt; and &gt; symbols in order to give the effect that you intended clearly. Thanks very much for this useful input. I’ll test this for myself soon 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: