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
2
Question by andrewproctor · Mar 20, 2019 at 01:04 AM · transform.position

Teleporting Character - issue with transform.position in Unity 2018.3

I am having some issues with teleporting my character in Unity 2018.3.7f1. I am using the FPSController, I created a "portal" with a capsule collider that has the "is Trigger" check marked. I also have created an Empty GameObject as a destination for the character to teleport to. I have a script that is below. It is attached to the portal with the capsule collider.

<--->

public Transform warpTarget;

public Transform thePlayer;

void OnTriggerEnter(Collider other){

thePlayer.transform.position = warpTarget.transform.position;

}

I have attached the empty game object to the warpTarget variable in the Inspector window and I attached the FPSController to the thePlayer variable in the Inspector window. It still doesn't work.

I teach a HS game design class and my lab was updated to 2018.3 2 weeks ago. Prior to updating, I had 2018.2 and it worked. It only stopped working after updating to 2018.3.

Does anyone have any work arounds or insight on how to get this to work? Any input is appreciated.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
15

Answer by Zarenityx · Mar 21, 2019 at 04:10 AM

Hard to tell from your question what the actual problem is and what isn't working.

If you're using the built-in FPScontroller, you're using the Character Controller, and the Character Controller has its own internal sense of its position and velocity. I'm not an expert on the inner workings of the character controller, but I know from encountering a similar bug that the character controller doesnt take kindly to being teleported around.

The solution I ended up using was pretty simply to turn the Character Controller off before teleporting, then on after. As simple as:

 CharacterController cc = thePlayer.GetComponent<CharacterController>();
 
 cc.enabled = false;
 thePlayer.transform.position = warpTarget.transform.position;
 cc.enabled = true;

When the Character Controller is re-enabled it should grab whatever position its at and start working from there.

Hope this works for you. This is what I had to do to get teleportation working.

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 andrewproctor · Mar 21, 2019 at 01:33 PM 6
Share

So, you were correct on it being the character controller. However, your script didn’t work. After reading your reply about the character controller I did another search. Found the resolution from Unity. Go to Edit > Project Settings > Physics and then check the box “Auto Sync Transforms”. Fixes the issue. Thank you for bringing the character controller to my attention!

avatar image Zarenityx andrewproctor · Mar 21, 2019 at 06:54 PM 0
Share

Ah. $$anonymous$$akes sense. Sorry about that. When I implemented my teleport it happened in FixedUpdate, so it didn't end up being necessary.

avatar image moqam andrewproctor · Jun 24, 2020 at 03:24 PM 0
Share

THIS IS WHAT FIXED IT $$anonymous$$Y GOD!

avatar image KodaKrome andrewproctor · Sep 05, 2021 at 05:34 AM 0
Share

This did it for me, I can't thank u enough. No where is transform sync mention in the documentation.

Show more comments
avatar image Twinklier · Feb 07, 2020 at 02:20 PM 0
Share

Works like a charm for me. THAN$$anonymous$$S

avatar image AlyaMcMelancholia · Feb 09 at 07:44 PM 0
Share

It worked for me, thanks ! Getting the transform position of a Character Controller is really strange, I couldn't have imagined it. Thanks for the answer to this ! I was begining to think that it was an unity bug

avatar image
-1

Answer by Ahmed_25 · Mar 20, 2019 at 07:48 AM

There will be a problem created by Vectors

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 andrewproctor · Mar 20, 2019 at 01:02 PM 0
Share

Could you elaborate or provide an alternate solution?

avatar image
0

Answer by PerfectSkies · Mar 20, 2019 at 04:10 PM

Try this for TP script:

  Vector3 tpLocation = new Vector3(13f, -12f, 0f); //Or warpTarget.transform.position.
 
 Quaternion startRotation = Quaternion.Euler(Vector3.zero);
 
 void OnTriggerEnter(Collider coll)
 {
   if(coll.gameObject.tag == "player")
   {
   thePlayer.transform.SetPositionAndRotation(tpLocation, startRotation);
   }
 }
 

*NOTE, YOU WILL HAVE TO ADD A PLAYER TAG TO YOUR PLAYER OBJECT FOR THIS TO WORK.

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 PerfectSkies · Mar 20, 2019 at 04:43 PM 0
Share

Oh also, it might help if you make "thePlayer" a GameObject, not a Transform. (I am used to moving game objects to a "Transform".

avatar image andrewproctor · Mar 20, 2019 at 05:27 PM 0
Share

Thanks for the script @rackomega but it didn’t work, unfortunately. I also made a mistake in the script I posted. I already had thePlayer as a GameObject, not a transform like I posted.

With your script, I added in the line:

Debug.Log(“$$anonymous$$ove $$anonymous$$e!”);

it gives me the message in my console, so I know it’s trying. It also has the look of glitching like it transformed me, then transformed back in a millisecond.

avatar image
0

Answer by Kakoha · May 11 at 07:50 PM

The problem here is that auto sync transforms is disabled in the physics settings, so characterController.Move() won't necessarily be aware of the new pose as set by the transform unless a FixedUpdate or Physics.Simulate() called happened in-between transform.position and CC.Move().

To fix that, either enable auto sync transforms in the physics settings, or sync manually via Physics.SyncTransforms right before calling Move().

source : https://issuetracker.unity3d.com/issues/charactercontroller-overrides-objects-position-when-teleporting-with-transform-dot-position

it resolved the problem for me !

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

111 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

Related Questions

Strange thing happening 1 Answer

Vertical Camera Orbit 0 Answers

transform.position is instantiating at the correct place but not staying there 1 Answer

I'm trying to displace a UI object in the opposite direction I move a scrollbar 1 Answer

2D Game Checkpoint & Respawning 2 Answers


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