• 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 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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 Controller follow mouse 2 Answers

i can't move anything , and nothing in Assest > Import Package any1 help me 0 Answers

move character controller smoothly to the object 1 Answer

Character controller wont move 0 Answers

Align move direction to a child object's facing direction 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges