Setting Teleporter Destinations

Continuing on with teleporters this post looks at having the script automatically calculate the offset required to reach the destination, rather than having to manually calculate and then enter the offset amounts into the sit target. This makes setting and/or changing the destination in the base teleporter prim extremely easy, requiring only the entering of a value for the destination vector to accomplish it.

To demonstrate the automatic calculation the following example has a prim at the sim coordinates X = 70.0, Y = 206.0, Z = 81.5 and a hypothetical destination of X = 80.0,  Y = 206.0, Z = 81.5. This destination requires an offset of 10 m on the X axis, the same as that used in the previous teleporter posts The Ubiquitous Teleporter and Teleporter Tweaks. The offset is calculated by subtracting the position of the teleporter prim from the destination using the function llGetPos to find the position of the teleporter prim.

Placed in the prim which is then clicked on, the following script demonstrates the calculation and shows the resulting offset vector, <10.0, 0.0, 0.0>, in the chat window.

default
{
state_entry()
{
}

touch_start(integer total_number)
{
vector offset = <80.0, 206.0, 81.5> – llGetPos(); // Subtracting the prim position from the destination giving the resulting offset as a vector
llOwnerSay((string)offset);
}
}

To set up the calculation in the teleporter using the final script from Teleporter Tweaks first initiate the destination vector as a variable at the beginning of the script and set its value. Then replace the offset vector in the function llSitTarget (in state_entry) with the calculation destination – prim position as shown. As mentioned above the llGetPos function is used to obtain the prim position value.

vector destination = <80.0, 206.0, 81.5>; // Change this variable to change the destination

default
{
state_entry()
{
llSetSitText(“Teleport“);
llSetText(“Click to Teleport“, <1.0, 1.0, 0.8>, 1.0);
llSetClickAction(CLICK_ACTION_SIT);
llSitTarget(destination – llGetPos(), ZERO_ROTATION); // Setting the offset using the calculation
}
// The remainder of the teleporter script
}

With the script developed to this point the teleporter prim can be placed at any coordinates in the sim and any destination within the 300 m limit can be set. The script must be reset when the prim is moved or saved when the destination vector value is changed, to embed the new sit target.

So is this the end of the teleporter script development. Well not quite. The script to this point does perform the teleportation, has instructional floating text for its use, single click capabilities and automatic calculation of the offset. But the teleportation is only as expected when the teleporter prim is set at zero rotation, i.e. X = 0.0, Y = 0.0, Z = 0.0. This is because the sit target is relative to the local coordinates of the prim and its rotation. If the prim is rotated, e.g. 45 degrees on the Z axis, the sit target (if the script is reset at this point) will place the teleportee the required offset but relative to the rotation, as shown below.

So there’s one more post to follow; dealing with the rotation of the teleporter prim and in addition, the rotation of the avatar as well. See you then.

Next in this Series: Adjusting Teleporter Rotations

Advertisements

2 thoughts on “Setting Teleporter Destinations

  1. Pingback: Teleporter Tweaks « F/Xual Education Services

  2. Pingback: Adjusting Teleporter Rotations « F/Xual Education Services

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