Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by THEtonyGUY · Aug 08, 2017 at 04:39 PM · teleporting

how do i teleport my player to an empty object?

note i'm new to coding so...i know almost nothing

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadyProductions · Aug 08, 2017 at 04:54 PM 0
Share

If you're new to coding you should learn the basics first and look through the unity tutorials.

avatar image Reynarz · Aug 08, 2017 at 05:07 PM 0
Share

As shady says: you Need learn to coding first. spend two or three moths learning the basics, and later start a project. You will thanks to us later...

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Arterion · Aug 08, 2017 at 04:57 PM

First of all you should answer the Question : How the Teleport should be triggered ?

If you wan't to teleport the Player in every State of the game by pressing a specific key your code look like this :

     private Transform PlayerTransform;
 
     public Transform TeleportGoal;
 
     //-------------------------------
 
     void Start ()
     {
         PlayerTransform = Gameobject.Find("Player").transform;    
 
                 // Reference the Player's Transform Component
     }
 
     //-------------------------------
 
     void Update ()
     {
         if(Input.GetKeyDown(KeyCode.E))
         {
             PlayerTransform.position = TeleportGoal.position
         }
     }

If you want to teleport the Player, when he moves into a Trigger you can use :

 void OnTriggerEnter ()
 {
     PlayerTransform.position = TeleportGoal.position
 }

or :

 void OnTriggerStay ()
 {
     if(Input.GetKeyDown(KeyCode.E))
     {
         PlayerTransform.position = TeleportGoal.position
     }
 }

Dont forget to add a collider to the gameobject where you put this script on and check the box "isTrigger";

I hope I could help :D

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image THEtonyGUY · Aug 08, 2017 at 05:54 PM 0
Share

one more thing when my player touches the trigger it says "The variable TeleportGoal of teleport has not been assigned". so i want to know how to make it go to the object labeled TeleportGoal I haven't had any experience with coding until now and would appreciate a reply.

avatar image arain55 THEtonyGUY · Aug 08, 2017 at 06:30 PM 1
Share

alright so this error is basically saying that the variable in the inspector has no transform component assigned to it. a transform component is the component with the position and rotation and scale labels on it, so what you need to do is make a new gameobject by right clicking on your hierarchy area and clicking create empty, this should create an empty gameobject, now name it TeleportGoal (name doesn't matter but for convenience...) now drag the TeleportGoal object to the TeleportGoal slot on the gameobject with the script attached to it

avatar image THEtonyGUY arain55 · Aug 08, 2017 at 06:55 PM 0
Share

ok thanks i didn't even notice!

Show more comments
avatar image
0

Answer by · Aug 08, 2017 at 04:59 PM

What do you mean by "teleport"?

If you want to go to the position of the empty object:

 player.transform.position = emptyObject.transform.position;

If you want to make the player a child of the empty object:

 player.transform.SetParent(emptyObject.transform);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by JTAGames · Jul 02, 2021 at 03:00 AM

https://www.youtube.com/watch?v=pNGwPrjnwfo

This is a more in depth look at teleportation in Unity. Pretty much the same thing except it is better suited to be used in complete projects.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

72 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Starship tractor beam and some sort of ftl jump 0 Answers

Teleport to the position of the prefab 1 Answer

How do I get to where the camera is 1 Answer

Player does not teleport to the right location 0 Answers

My teleport works only with going forward. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges