Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Jamz · Jan 20, 2013 at 05:55 AM · gameobjectphotonteleport

Teleport player script

Hey everyone,

I need a script that when any object touches my "teleporter" they are teleported to another location. I'm using photon and the players are made on runtime. (In other words the players don't have there own gameobject, when they start the game the object is made.)

Thanks.

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

2 Replies

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

Answer by Loius · Jan 20, 2013 at 06:09 AM

 var targetPosition : Vector3;
 
 function OnTriggerEnter( other : Collider ) {
   other.transform.position = targetPosition;
 }
Comment
Add comment · Show 8 · 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 Jamz · Jan 20, 2013 at 06:43 AM 0
Share

Where should I attach this on to? Should I attach it onto the teleportation pad?

avatar image Loius · Jan 20, 2013 at 07:01 AM 0
Share

yeah.

don't forget to work through a worthwhile tutorial at some point.

avatar image Jamz · Jan 20, 2013 at 12:43 PM 0
Share

it didn't work. I made the player collide/hit the object and nothing happened.

avatar image Loius · Jan 20, 2013 at 05:48 PM 0
Share

read about collisions, then. you need a trigger volume.

i'm being intentionally vague because this is extremely basic stuff and if I just tell you everything you'll miss out on important learningstuffs. :)

avatar image Jamz · Jan 21, 2013 at 02:15 AM 0
Share

$$anonymous$$any thanks to Loius and person who answered. I understand it now :~D

Show more comments
avatar image
0

Answer by shieldgenerator7 · Apr 01, 2019 at 01:00 AM

If Loius' answer doesn't work for you, make sure the object you're trying to teleport has a PhotonView and a PhotonTransformView attached to it. And make sure you add the PhotonTransformView to the PhotonView's Observed Components list.

alt text


If that doesn't work, or you also have to sync your Rigidbody2D, you can add a PhotonRigidbody2DView to your object in the same way. alt text


If it still doesn't work, try replacing gameObject.transform.position = targetPosition; with a call to teleportObject():

 IEnumerator teleportObject(GameObject go, Vector3 newPosition)
 {
     Rigidbody2D rb2d = go.GetComponent<Rigidbody2D>();
     rb2d.isKinematic = true;
     while (go.transform.position != newPosition)
     {
         go.transform.position = newPosition;
         yield return null;
     }
     rb2d.isKinematic = false;
     yield return null;
 }


You can call this method with:

  StartCoroutine(teleportObject(gameObject, targetPosition);


You might also be able to get away with just setting Rigidbody2D.isKinematic = true; before setting the position and then just setting it back with Rigidbody2D.isKinematic = false; at the end, but I haven't tested it.


unity-photon-question-teleport-transform.png (17.4 kB)
unity-photon-question-teleport-rigidbody2d.png (27.9 kB)
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

11 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

Related Questions

Multiplayer game, object instantiated is being added for every single player 1 Answer

A node in a childnode? 1 Answer

Collecting game objects in specific order 1 Answer

C# Check If Gameobject is within Collider 1 Answer

How to instatiate two players simultaneoulsy before loading level 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