Saturday, August 30, 2014

Unity Tutorial: Easy Teleport in JS

UnityGirl's Easy Teleportation

_______________________________________________________

Whether it's SciFi or Fantasy, many games make use of convenient teleportation. There are several ways to do this in Unity, and some of them are a lot bigger pains than others. Here's the quickest, easiest way I've found to get your character where it needs to be with no guessing at large world coordinates.

Teleporter Setup

This works along the same principle as the Building Instantiator, using an existing Game Object in the scene to represent where we want to go.

Capsule Locator Sitting in a Chair

Locator

Create a GameObject to represent where you want your character to be

I use one I can see, then turn off the Mesh Renderer and Collider

Put your Locator object wherever you want your player to teleport to

make sure it's high enough you won't fall through the floor/ground

TURN OFF the Mesh Renderer** and any Colliders***

Name it something recognizable

_______________________________________________________

Setting Player Tag

Player

Make sure your player has the "Player" tag

And that nothing you don't want to teleport doesn't

_______________________________________________________

Script

Establish your Locator

Find your Player

Tell the Player to be at the Locator based on some criteria

We're using OnMouseDown so clicking the script-bearing object will trigger the 'port.