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 Slaifir · Mar 29, 2020 at 10:15 PM · scene-loadingmovecharacter controllerrespawningscript execution order

Character Controller Move returning player to the start

Hello everyone,

I'm working on a 2D runner, and I have been running into this problem for months. Basically I have this checkpoint system not destroyed on load, and when a level is restarted the Checkpoint Manager teleports the player to the latest checkpoint. Most of the time this works, but sometimes at random the player respawns back at the beginning. I have determined through repeated testing that the Checkpoint Manager is properly, but something else is moving the player back to the beginning.

The culprit is the PlayerController script I have, specifically this block:

             currState.OnStateUpdate(this);
 
             if (IsDead)
             {
                 movement.x = 0;
             }
 
             characterController.Move(movement * Time.deltaTime);
 
             if (gameInput.PathDownButtonUp && followPath.node.leftParellelNode != null)
             {
                 followPath.node = followPath.node.leftParellelNode;
             }
 
             if (gameInput.PathUpButtonDown && followPath.node.rightParellelNode != null)
             {
                 followPath.node = followPath.node.rightParellelNode;
             }
 
             lastYAxis = gameInput.Axis.y;


I have placed some debug statements and narrowed down the issue to the line

 characterController.Move(movement * Time.deltaTime);

Before it, the position of the player is (196.0, 0.4, -1.0), which is the one they are teleported to by the CheckpointManager. However, after that line the player is somehow teleported back to the start at (-50.4, 0.4, -1.0)

I have confirmed that the vector is not a negative number that would move the player back to that position. The variable Movement is working as intended as well. So there must be something wrong with the CharacterController that keeps causing this. Can anyone help me solve this?

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
0

Answer by MrFingers · Jan 05, 2021 at 04:54 PM

Hi. I had the same problem and fixed it by doing this:

     bool hasloaded = false;
 
     void Start()
     {
         StartCoroutine(WaitForLoad());
     }
 
     void Update()
     {
         if (hasloaded)
         {
             // Your movement code here
         }
     }
 
     IEnumerator WaitForLoad()
     {
         yield return new WaitForSeconds(0.5f);
         hasloaded = true;
     }


I'm not sure if it's the best solution (I'm kinda new to programming), but it fixed it for me at least! :)

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

130 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 avatar image avatar image avatar image avatar image avatar image avatar image 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

Character Keep On Moving Without Pressing Button 0 Answers

Problems with CharacterController.Move 1 Answer

Character controller move not working 0 Answers

Jumping with Character Controller?! 1 Answer

i can't move anything , and nothing in Assest > Import Package any1 help me 0 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