- Home /
Teleport Script?
Greetings! I want to create a kind of teleport script and i'd like to know if there is an easy approach to it. Let me give you an example about what kind of teleport i'd like to have. So, you have a First Person Controller and as soon as you see a cube near it and click with your mouse, the FPC "teleports" on the cube. Is that possible? I was thinking about Vector3 and that kind of stuff :P Thanks
Answer by Roland1234 · Dec 02, 2013 at 07:57 PM
This is really a very generic question, but the short answer would be: yes - just set an object's transform.position to whatever position you want the object to "teleport" to. A more complete answer would require to know more specific requirements. You mention clicking on a cube to teleport on it: a Raycast using a ray constructed from the mouse position and camera would give you which cube the player has clicked on (provided the cube has a collider), and the teleport position could be derived from that (whether you want the cube's actual position or a position relative to it, like the top of the cube, etc).
The main caveat to consider would be finding a way to determine whether or not the resulting teleport is valid, which you should be able to accomplish using Physics methods like CheckCapsule. More specific details would require more specific questions.
Answer by flaviusxvii · Dec 02, 2013 at 07:52 PM
If you have a Rigidbody:
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.MovePosition.html
Otherwise you can just change the position
gameObject.transform.position = ..some new position..
Answer by TimBorquez · Dec 02, 2013 at 07:59 PM
look into moving something
centering the mouse in the middle of the screen
and look up raycasting to mouse the position to figure out how to find a spot to move to
Your answer
![](https://koobas.hobune.stream/wayback/20220613123245im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Disable First Person Controller upon death. 4 Answers
Multiple Cars not working 1 Answer
Declaring a Vector3 variable in C# 1 Answer