Recipe 3.5: Teleport Pad
Buildings in Second Life often have more than one level. There are three common methods for allowing users to move from one level to another, they are:
- Stairs or Ramps
- Elevators
- Teleport Pads
Stairs and ramps do not require any scripting. The user walks up them. Elevators and teleport pads require scripting. This chapter provides a recipe for each.
This recipe provides a simple teleport pad. A teleport pad is more flexible than an elevator. The teleport pad can send the user to a specific point, within 300 meters, in the same region. The teleport pad recipe is shown in Listing 3.5.
Listing 3.5: Teleport Pad (Teleport.lsl)
// From the book: // // Scripting Recipes for Second Life // by Jeff Heaton (Encog Dod in SL) // ISBN: 160439000X // Copyright 2007 by Heaton Research, Inc. // // This script may be freely copied and modified so long as this header // remains unmodified. // // For more information about this book visit the following web site: // // http://www.heatonresearch.com/articles/series/22/ vector target=<190, 197, 64>; vector offset; default { moving_end() { offset = (target- llGetPos()) * (ZERO_ROTATION / llGetRot()); llSitTarget(offset, ZERO_ROTATION); } state_entry() { llSetText("Teleport pad",<0,0,0>,1.0); offset = (target- llGetPos()) * (ZERO_ROTATION / llGetRot()); llSetSitText("Teleport"); llSitTarget(offset, ZERO_ROTATION); } changed(integer change) { if (change & CHANGED_LINK) { llSleep(0.5); if (llAvatarOnSitTarget() != NULL_KEY) { llUnSit(llAvatarOnSitTarget()); } } } touch_start(integer i) { llSay(0, "Please right-click and select Teleport"); } }
The teleport script uses two global variables. They are.
vector target=<190, 197, 64>; vector offset;
The target is the coordinate that the teleport script should send the user to. The offset is calculated based on the target and the current position of the teleporter. The offset is the distance that must be traveled to reach the target, starting from the teleporter.
Whenever the teleport pad is moved, the offset must be recalculated. The sit target is then updated.
moving_end()
{
offset = (target- llGetPos()) *
(ZERO_ROTATION / llGetRot());
llSitTarget(offset, ZERO_ROTATION);
}Likewise, when the teleport pad is first created, the offset must be recalculated. Additionally, the sit text is specified. Rotation is also taken into account and neutralized.
state_entry()
{
llSetText("Teleport pad",<0,0,0>,1.0);
offset = (target- llGetPos()) *
(ZERO_ROTATION / llGetRot());
llSetSitText("Teleport");
llSitTarget(offset, ZERO_ROTATION);
}When a user sits on the teleport pad, their avatar sits at the target location. The avatar is then stood up.
changed(integer change)
{
if (change & CHANGED_LINK)
{
llSleep(0.5);
if (llAvatarOnSitTarget() != NULL_KEY)
{
llUnSit(llAvatarOnSitTarget());
}
}
}The teleport pad is a form of Linden Scripting Language trick. By specifying a distant coordinate for the sit target, the avatar is moved to that distant location and then stood up. This instantaneously moves the avatar to the new location. The avatar is able to move through walls and anything else that is in the way.












