How to create teleporter objects in Jibe and Unity3d

It’s fun to walk, run and fly around in a Jibe world.  Multiuser 3d virtual worlds like Jibe are at their best when you explore them.  You never know what you might discover over the virtual horizon.

If you want to give visitors in your Jibe world the ability to instantly “teleport” from one location to another, you can easily set that up too.  Today we’ll learn how to set up any object in your Jibe world so that, if you click on it, your avatar is instantly teleported from one place to another.

If you’re a current Jibe customer, you’ll find a detailed section in the Jibe User Manual and Developer Reference (downloadable here) that explains how to set up “Teleport Links.”  This gives you the ability to add buttons on the Jibe User Interface that will teleport avatars to any locations you wish to define.

But what if you want to create an inworld object like a sign or a door that, when an avatar clicks on it, automatically teleports them somewhere?

Here’s how you can set it up in a few simple steps.

– Step 1: Create a New Script

Fire up your Unity editor and create a new C# script.

How to create a new C Sharp script.

Name this script “ClickObjectTeleport” and double-click on it in your Project window to start editing it.

New script is now properly named.

Paste the following code into your new ClickObjectTeleport script.

using UnityEngine;
using System.Collections;
using System;

public class ClickObjectTeleport : MonoBehaviour
{

public int spawnVariance = 0;
private static System.Random random = new System.Random();
public bool showTeleportParticleEffect = true;
public GameObject teleportParticleGenerator;
public Transform teleportDestination;

void OnMouseOver()
{
if (Input.GetMouseButtonDown(0))
{
DoTeleport(teleportDestination);
}
}

void DoTeleport(Transform target)
{
string localPlayerName = “localPlayer”;
GameObject localPlayer = GameObject.Find(localPlayerName);

float offsetX = random.Next(spawnVariance);
float offsetZ = random.Next(spawnVariance);

Vector3 newPosition = target.position;
newPosition.x = target.position.x + offsetX;
newPosition.z = target.position.z + offsetZ;

localPlayer.transform.position = newPosition;
localPlayer.transform.rotation = target.rotation;

if (showTeleportParticleEffect)
{
if (teleportParticleGenerator != null)
{
Instantiate(teleportParticleGenerator, newPosition, target.rotation);
}
}
}
}

– Step 2: Put your script inside an object

You can place your ClickObjectTeleport script inside any object in your Jibe world that you want to use as a clickable teleportation device.  Let’s use a cube for this example.

How to make a basic cube GameObject.

Your cube sitting in your scene.

Now, go to your Project window and drag your ClickObjectTeleport script into your cube object.

Your ClickObjectTeleport script inside your cube.

Find a copy PlayerParticles in your Project folder and drag it onto the Teleport Particle Generator field in the Inspector settings.  This will generate a nice particle effect when avatars teleport.

Drag this into the proper field in the Inspector window.

All set.

The last thing you need to add is the Teleport Destination.  We’ll do that in the next step.

– Step 3: Set up a Teleport Destination

Find the location where you want an avatar to arrive when they teleport and create an empty GameObject at the precise point you want the avatar to appear.

Creating an empty GameObject.

Your empty GameObject in your scene.

Rename your empty GameObject something like Teleport arrival point so you can easily find it in your Hierarchy window.  Remember, it will be invisible in your scene!

Now go back and select the teleporter cube you created, go into the Inspector window, and drag your Teleport arrival point object from your Hierarchy onto the Teleport Destination field in the Inspector settings.

Perfect!

You’re done!

Log in to your Jibe world, walk your avatar up to the teleporter cube, and click on it.  You’ll immediately appear in a shower of particles at the location of your Teleport arrival point object.

You can try this out in my own Jibe world.  I’ve set up a sign in my arrival area that lets folks take a trip to my windmill far across the landscape.

Beam me up.

It works!

If you want to learn more about Jibe, be sure to join our Jibe-Unity3d Google Group for lots of great discussions and idea sharing.

-John “Pathfinder” Lester

8 thoughts on “How to create teleporter objects in Jibe and Unity3d

  1. Cooooool… Now figure out how to teleport to other Jibe worlds, other OpenSim regions, and even Second Life. 🙂 Right! Maybe in 5 years…

  2. Hey, I tried to chase your rabbit into the glowing rock and could not. 😦
    I also love your idea of creating teleport portals. Would be cool if I could chase your rabbit into the glowing hole in the rock and find myself falling (due to the instant teleport), down the rabbit hole into an entirely new scene! I opt for the Mad Hatter’s Tea Party to be at the other end of the fall!

  3. That’s pretty easy to do! In the “ClickObjectTeleport” script in this tutorial, just find the bit that says:

    void OnMouseOver()
    {
    if (Input.GetMouseButtonDown(0))
    {
    DoTeleport(teleportDestination);
    }
    }

    And replace it with THIS code:

    void OnTriggerEnter(Collider other)
    {
    DoTeleport(teleportDestination);
    }

    Now save it as a new script called something like “CollideObjectTeleport.” Drop it into a GameObject and make sure the “Is Trigger” option is selected.

    Voila. When your avatar collides with the GameObject, you will be teleported!

    I’ve just modified my own Jibe world so that the glowing yellow rabbit portals in the ground take you to the rabbit’s spaceship. 🙂

  4. In Unity 3.3 when I copy and past this scipt as a C# script I get the error message…
    Assets/ClickObjectTeleport.cs(24,27): error CS1525: Unexpected symbol `’

    thanks, Chris

    • Aha, I suspect you might be getting the classic “weird quote characters” issue that sometimes happens when copying/pasting from a webpage.

      Just go in to the code and make sure all the quotes (both single and double) are standard ASCII symbols. NOT the italicized-looking versions.

  5. Hi,

    What is the PlayerParticles object and where do I find it? I created a new project and imported the Standard Assets, followed your instructions, but couldn’t find that object.

    • I found it! Somehow it went missing in my Standard Assets folder. I re-imported it and it works!

      On a side note, how can I make it so that the particles will disappear after a few seconds?

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