- Home /
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.
Answer by Brascal · Jul 16, 2015 at 09:15 AM
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.
Answer by Quaker_SDR · Oct 02, 2014 at 08:57 AM
void OnTriggerEnter(Collider other) { transform.position=<Desireposition>; }
Answer by leowu4ever · Oct 02, 2014 at 10:25 AM
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.
Answer by Shirokov · Jul 09, 2015 at 06:31 AM
Have you tried to watch the teleporter grenade tutorial?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Need help making an audio trigger. 2 Answers
Quick Custom Inspector Question 1 Answer
Glitchy Turret Script 2 Answers
Problem with OnTriggerEnter() 1 Answer