Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by ahkatz5 · Jan 07, 2019 at 01:27 AM · first-person-controllerteleporting

First Person Player Teleportation

I'm sure this dead horse has probably been beaten many times over, but I can't seem to find an answer to my particular problem...

I am attempting to set up up a simple trigger to teleport the first person character to another location with the following script:

 void OnTriggerEnter(Collider trig)
 {
     if(trig.gameObject.tag == "WarpTrig")
     {
   
         transform.position = destination.transform.position;

     }
 }



This script is currently attached to the FPS Controller. I can see that the player is teleported for what seems like one frame, but then the player is right back to standing in the trigger. Your help is much appreciated!

Comment
Add comment · Show 1
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 Cornelis-de-Jager · Jan 07, 2019 at 01:56 AM 0
Share

Can you post your moving script here as well?

10 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by boris1709 · Nov 07, 2019 at 04:45 AM

Sorry for bumping this, but I found a fix to the problem caused by the FirstPersonController.cs script.

If you teleport the character, simply turn off the FPS controller script, and then set a boolean to true that will turn the script back on the next Update() call.

An example is below

 void Start()
 {
     turnOnMovementNextTick = false;
 }
 void Update()
 {
     if (turnOnMovementNextTick)
     {
         movementScript.enabled = true;
         turnOnMovementNextTick = false;
     }
     if (Input.GetKeyDown(KeyCode.L))
     {
         movementScript.enabled = false;
         transform.position = new Vector3(15.32f, 0.97f, 9.54f);
         turnOnMovementNextTick = true;
     }
 }
Comment
Add comment · Show 1 · 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
1

Answer by herzog_deair · Apr 21, 2019 at 09:14 AM

First Person Controller script keeps the player back at old position. If I disable that script, transform.position works very well, but then I can't move the player :D

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
1

Answer by nik_bluebird · Apr 19, 2019 at 11:33 AM

Hi,

OnTriggerEnter() event only called when you attached Collider component on both game objects and one of them should have attached Rigidbody component. Also make sure, 'Is Trigger' property should be checked, in any one of Collider.

For more details:

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html

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
1

Answer by jemmysponz7 · Oct 13, 2019 at 10:15 AM

It's been a bit since you posted this, but I had the same question! After some digging, I found what worked best for me was briefly enabling autoSyncTransforms during when the teleportation was actually happening. https://docs.unity3d.com/ScriptReference/Physics-autoSyncTransforms.html

Comment
Add comment · Show 1 · 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 mechanic_kharkov · May 26, 2021 at 06:59 PM 0
Share

THANK YOU! It worked for me. Actually, not autoSyncTransformsms, but Physics.SyncTransforms() right after the transform.position change. It tried to make me nuts. Thank you again.

avatar image
1

Answer by Kieran-Brown · Apr 26, 2020 at 03:39 AM

This is a dead horse, and I am sorry for making it walk around like a zombie 1 year later.... But as herzog_deair said, the way the FirstPersonController prefab from standard assets is coded has it's own set of rules, I am fairly new to Unity and was struggling a lot with this for months trying to make a teleport work.

The very simple fix I found is to just use the RigidBodyFirstPersonController prefab (or something like that), any of the other standard assets prefabs should work fine with transform.position, they may need a little polishing though to meet your desired needs, but they work.

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
  • 1
  • 2
  • ›

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

112 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 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

FPS teleport flicker one frame- but works fine with main camera. 2 Answers

Game Pauses when I teleport player 2 Answers

First Unity tryOut - First Person Controller makes all objects just Float away... 3 Answers

Move Character Controller along Box 0 Answers

Sphere Controller Help? 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