Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Hexer · Aug 02, 2013 at 10:22 AM · collidertransformpositionplayerteleport

Teleporting Player to a point using box colliders

I got some problem with teleporting my character to a certain point.

 var TelePosition : Vector3;
 
 function OnTriggerEnter(other : Collider) 
 {
     if (other.tag == "Player") 
     {
     transform.position = TelePosition;
     }        
 }
 
 // Box Collider Is Trigger must be checked to work.
 // Change the transform.position coordinates in the Inspector.

This is the code i wrote. The idea is that if my player falls off the map and collide with the box collider, the player gets respawned or teleported to a different location that i have given with var TelePosition : Vector3;

Now the problem is that when collide, the Player don't get teleported to that location. Instead the Box Collider decide it can teleport to that point.

alt text alt text

*notice that i already tag my character with the tag : Player

So any idea what the problem is? I appriciate some help :)

help2.png (292.1 kB)
help1.png (275.2 kB)
Comment
Add comment
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

1 Reply

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

Answer by EHogger · Aug 02, 2013 at 11:47 AM

transform.position is the position of the object your script is attached to, which in this case is your box. Change it to other.transform.position = TelePosition and it will move the object that hits it instead (the player).

Comment
Add comment · Show 2 · 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 aldonaletto · Aug 02, 2013 at 12:30 PM 1
Share

That's right. And it would be better to define the destination point with an empty game object ins$$anonymous$$d of a Vector3: it's easier to set the position in the Editor, and you can define the rotation as well:

 var TelePosition : Transform; // drag the destination empty here
  
 function OnTriggerEnter(other : Collider) 
 {
     if (other.tag == "Player") 
     {   
      // move and align the player to the destination empty GO
         other.transform.position = TelePosition.position;
         other.transform.rotation = TelePosition.rotation;
     }        
 }

This avoids the embarrasing situation where the player gets teleported to the destination point but keeps looking in the old direction.

avatar image Hexer · Aug 02, 2013 at 01:22 PM 0
Share

Thanks guys, both of you. I already thought i was missing something but couldn't put my finger on it.

The idea to put an empty game object ins$$anonymous$$d of just a Vector3 coordinate is a smart idea, so i could just drag or change the position. I didn't really need to change the rotation of the object because i let my character respawn in the middle of the map without walls or objects around it that could probably hinder the player.

I will re$$anonymous$$d it for my next project, probably usefull in a teleport game :).

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

16 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

Related Questions

Need enemy to follow only active character 0 Answers

c# how to change player location on 0 hp 1 Answer

Transform.Position Help 3 Answers

transform.position sends object to wrong position 1 Answer

Game Object won't match rotation of new positions transform 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