Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2020.3 LTS no longer lets CharacterController.Move() and RotateAround() work simultaneously?

Discussion in 'General Discussion' started by adhochero, May 14, 2021.

  1. adhochero

    adhochero

    Joined:
    Feb 2, 2017
    Posts:
    43
    So.. with unity 2020.3 LTS, i have noticed you can no longer use CharacterController.Move() and RotateAround() at the same time. I previously used RotateAround() while climbing in VR to pivot around your climbing hand when you use the rotate input. but now its all F***ed up. if you wanna see what i mean you can use this:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(CharacterController))]
    4. public class RotateAroundTest : MonoBehaviour
    5. {
    6.     CharacterController characterController;
    7.     [SerializeField] Transform rotateAroundThis;
    8.     [SerializeField] bool enableCCMove = true;
    9.  
    10.     void Start()
    11.     {
    12.         characterController = GetComponent<CharacterController>();
    13.     }
    14.  
    15.     void Update()
    16.     {
    17.         if(enableCCMove)
    18.             characterController.Move(Vector3.zero * Time.deltaTime);
    19.  
    20.         if(rotateAroundThis)
    21.             transform.RotateAround(rotateAroundThis.position, Vector3.up, 100 * Time.deltaTime);
    22.     }
    23. }
    24.  
    just add this script to a gameobject and put the main camera as a child (as if its a simple player controller). then create a cube in the scene and set as the rotateAroundThis transform in the RotateAroundTest script in the inspector. you can see how it should be working by unchecking the enableCCMove bool to false.

    if anyone can find a fix please let me know.
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,745
    Just for a laugh, what happens if you switch the order of the conditionals?
     
    Joe-Censored likes this.
  3. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,000
    Could this be something to do with the changes made to physics ( I’m assuming the character controller move call uses physics ), where unity will no longer update physical objects when you make the change but rather later on in the frame. This was done to make physics more efficient. There should be a call you can make to force the physics to update, unfortunately I don’t remember what it is off-hand, but a bit of Googling should find it.
     
  4. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    417
    CharacterController movement has nothing to do with physics.
     
  5. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,000
    Since the character controller uses a capsule collider it does has something to do with physics. The question is whether the move call is using physics under the hood to perform this move in which case it might be affected by the change I mentioned.
     
  6. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    417
    Collision != Movement
     
  7. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,745
    CharacterController's movement is handled separate from the rest of the Unity physics engine, which is one of the reason that Rigidbody based systems get recommended instead. CharacterController uses a capsule for physics, but it doesn't engage with physx in any capacity.
     
  8. TPEUnity

    TPEUnity

    Joined:
    Jan 17, 2018
    Posts:
    36
    Seems to rotate correct if rotation is done in Fixed Update. If i remember correctly CharacterController is never supposed to be rotated.
     
    Last edited: May 17, 2021
  9. adhochero

    adhochero

    Joined:
    Feb 2, 2017
    Posts:
    43
    weird. yeah it works great in fixed update. why are you not supposed to rotate? how would a player turn around then? either way just moving the rotateAround to fixedUpdate allows them both to play nice together again. thanks.
     
    Last edited: May 18, 2021
  10. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,745
    Generally by adjusting the rotation directly or not using the character controller, which I am getting the feeling may not be long for this world.
     
  11. TPEUnity

    TPEUnity

    Joined:
    Jan 17, 2018
    Posts:
    36
    Well its really guesses from me since it really is a black box but i think its based on (or is) nvidia physx kinematic controller and internally its always in fixed rotation and does not seem to support rotation.
     
  12. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,745
    Factually untrue. I've rotated character controllers plenty.
     
  13. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    417
    Ok... So, like many here (i assume), I work in the software industry. (Not gaming). But if you can prove this worked a certain way all along and then changed suddenly in a new release, you should file a bug report. No one here is likely to be able to tell you if this is "meant to be" or not.
     
    angrypenguin likes this.
  14. stain2319

    stain2319

    Joined:
    Mar 2, 2020
    Posts:
    417
    ...That's what I'd tell my customers anyway.
     
  15. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,745
    The problem is that, like all Unity black boxes, there's no real line of communication there if the answer ends up being "working as intended."
     
  16. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,000
    Incorrect!

    Since once I found 10 minutes to install 2020.03 and test my theory, it proved that not only does the CharacterController use Physics, it was the change to syncing transforms in Unity that has caused this issue.

    You'd think there would have been a clue in the fact that the 'CharacterController' component itself is included under the 'Component > Physics' menu.

    Simply adding Physics.SyncTransforms() in the OP's script appears to fix the issue! At least the only issue I could see from running their original test script in a simple scene as they never specified the exact issue, which to me appeared to be that the charactercController end up rotating 360 around its local origin as well as rotating around the target cube.

    Try it for yourself
    Code (CSharp):
    1. using UnityEngine;
    2. [RequireComponent(typeof(CharacterController))]
    3. public class RotateAroundTest : MonoBehaviour
    4. {
    5.     CharacterController characterController;
    6.     [SerializeField] Transform rotateAroundThis;
    7.     [SerializeField] bool enableCCMove = true;
    8.     [SerializeField] bool enableSync = true;
    9.  
    10.     void Start()
    11.     {
    12.         characterController = GetComponent<CharacterController>();
    13.     }
    14.     void Update()
    15.     {
    16.         if ( enableCCMove )
    17.             characterController.Move( Vector3.zero * Time.deltaTime );
    18.    
    19.         if(rotateAroundThis)
    20.             transform.RotateAround(rotateAroundThis.position, Vector3.up, 100 * Time.deltaTime);
    21.  
    22.         if ( enableSync )
    23.             Physics.SyncTransforms();
    24.     }
    25. }
    It should be noted that while toggling 'enableSync' on/off will toggle between the unexpected and expected behavior it will also 'de-sync' the overall view rotation. That is if you toggle 'enableSync' on/off the camera will likely be looking the wrong way, but it will at least now be fixed to that direction instead of rotating around like a mad.

    It should also be noted that 'Physics.SyncTransforms()' is global, so calling it here you sync all transforms in the scene, when all we really might want to do is sync just the characterController. Perhaps there is a more fine-grained calll under physics that could do that. Though I see from past comment that performing it in FixedUpdate() will fix the issue too, so maybe that is a better approach.
     
  17. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,000
    I don't think this is either working as expected or not as its kind of caught in a limbo between and as such is unlikely to be addressed.

    As I showed this is due to the change in how Unity performs physics updates on transforms ( yes the CharacterController (CC) does use Physics! ) and this is a low-ish level optimization strategy that can and does provide substantial benefits to performance. To force all transforms to sync whenever they change just to make the CC work would effectively neutralize this optimization so its not something that I see Unity doing.

    While performing the op's code in fixedUpdate appears to also address the issue ( as a post above describes) that isn't part of the CC so I don't see that being changed to fix the problem either. I guess maybe they could change the CC code to work with fixedUpdate, but that runs the risk of breaking existing code or adversely affecting performance so again don't see that being done.

    Honestly I think at best we can hope for is someone highlights the issue to Unity and they add some disclaimer to the CharacterController and inform developers if they need the old behavior to work they will have to add a Physics.SyncTransforms() call and forego any of the optimizations that would have brought.
     
  18. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,905
    You understand the problem you have the best, apparently you found solution to it too. You have access to the documentation, why wouldn't you be that someone? You can send messages under every documentation page to Unity, all you need to do is to navigate to the CharacterController documentation page and ask them to add more info on this. If you copy+paste your text above for them, they will know what you expect to put there too.
     
    stain2319 likes this.
  19. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,000
    Because after more than a decade of trying to help Unity and producing extensive bug reports that take hours or days and being ignored or never fixed I decided I had better things to do with my time.

    Years of neglect from Unity themselves have led to this and I’m not alone in deciding to walk away from bug reporting.
     
  20. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,745
    Yeah there's basically no point in reporting things to Unity. If there was, the Feedback section would have been more than a corral for people desperately wanting Unity to fix its S*** before it was shut down.