How can I teleport objects.

Hey, so I thought it would be meaningless to post such a short and easy script so I thought I might as well just ask the question.
Call me noob, but is there a way I can get my character controller to teleport to a certain position on the axis without switching scenes when I enter a trigger area?

If you can help, can you please demonstrate a simple example script of how this could work using a trigger. Help would be greatly appreciated, Thanks.

4 Answers

4

void OnTriggerEnter(Collider other) { transform.position=<Desireposition>; }

Thanks for the help.

I assume you talking about teleport a GameObject in one scene. That means you try to change its position. You can specify a destination by placing a Quad on a certain position.

For the place you want to enter and do the teleport, just attach a script which contains OnTrigger method. Like below.

Let me know if you still having problem.

Have you tried to watch the teleporter grenade tutorial?

Here is a completed script for teleporting object. Add this object witch will teleport player a new place.

public Transform exit;
public Transform myplayer;

void OnTriggerEnter(Collider other)
{
if (other.CompareTag(“Player Event Trigger”))
{

        myplayer.position = exit.position;
      
       // Camera.main.transform.position = new Vector3(myplayer.position.x, myplayer.position.y, -10);// this code if you want make 2D game. Or you have a 3 person animation camera
    }
} 

Remember public Transform exit will be a empty game object witch spawn player.

If you have more than one teleport exit areas. Make a array public enum. Enum you can choose what port will be execute.