Hey folks!
I’m trying to warp my player to a certain position when it collides with a gameObject.
The collision works fine, but when I try to set the players position, using
transform.position = newPos.position;
Nothing happens.
The player stays at exactly the same position.
This script is attached to the player gameObject.
It’s driving me crazy.
Perhaps it’s conflicting with the move script I have in the Update function (the usual controller.SimpleMove()), but I bypassed it and it still didn’t do anything.
No errors either.
So I searched long and hard to see if there’s a different way to set the position of my player, but everyone seems to have success using transform.position…
Your CharacterController probably overrides your transform changes (it behaves more or less like a Rigidbody). You can try to store this new position and execute transform.position assignment in LateUpdate function in your script.
Thanks for the help dude. I tried it in the lateUpdate() function but it STILL won’t budge. Player just keeps on going at the same location. Collision is true.
I can’t believe I can’t figure this out!! Something THIS simple!
…
Put a Debug.Log(transform.position) after the position change. If it prints out that you’re at your old position, it failed. If it prints out that you’re in your new position, then you’re moving something that doesn’t contain all the pieces of your player.
I know this is very old, but it’s one of the few results that google gave to me when searching for a similar problem. I can confirm that a character controller will reset your direct transform.postion changes back to the previous location. If you wish to directly set the transform for a teleport or whatever you can fix this with:
THANK YOU! I just ran into this today with Unity 2018.3.0f2, previously I never ever had this problem with the CharacterController. I actually thought I was going crazy. You sir are a life saver.
While this fixes the position issue, set rotation for me is still 100% broken. I haven’t been able to get my character controller to use the new Rotation of my Target Game object to save my life.
What I myself am trying to do.
I have a game object that I can place into the scene that acts as a sort of Target to set the Rotation and Position from. With turning off the CharacterController, I can now easily move the controller, but I can’t rotate it away from what it was before the transform adjustment was called. even with turning off the CharacterController while this happens.
Maybe I am going about this wrong, but it would follow that if you can move the CharacterController in this way, you should also be able to rotate it like this as well. But apparently not.
Hi, giving my two cents on this question, i ran into this problem this day. I Believe that all is about the characterController, but i did not find a response in time so first of all thanks you for the enable/disable trick.
For the rotation, you can do the same thing by changing the maincamera rotation to keep the rotation you want. The disadvantage of this is that it broke the direction system, apparently based on the initial camera rotation.
So time to make our own CharacterController am i wrong ?
Thanks for these posts. Been pulling my hair out on this. I think I have a debug statement about ever other line of the FixedUpdate method of the FirstPersonController script. Confirmed it was the characterController.Move() call that was resetting my players position.
This was amazingly helpful. Had been trying to turn off the alterations of CharacterController for days with no solution from my search until this post. Great stuff