Search Unity

Character Controller Move with a moving parent in 2018.3

Discussion in 'Physics' started by gambitsunob, Oct 14, 2018.

  1. gambitsunob

    gambitsunob

    Joined:
    Apr 17, 2018
    Posts:
    1
    I'm having some issues with using a Character Controller and calling Move in 2018.3. Trying to figure out if it's a bug, if I'm using it wrong, or something else? It did work in 2018.1 but I couldn't find anything googling/searching.



    A few states here.

    A) Fixed Update Platform - Fixed Update Character Controller
    Calling CharacterController.Move causes it slide off even though it's parented, it's like the parents transform no longer affects it. If I don't call CharacterController.Move, it starts working as I expect it to and follows along, I just can't move the player capsule then.

    B) Fixed Update Platform - Normal Update Character Controller
    Doing it this way, the Character Controller follows along with the Platform. Though this doesn't seem like the correct solution. The move should be called in the Fixed Update.

    C) All other ways the controller slides off the platform and doesn't use the parenting.

    So my real questions is. Is this the intended functionality, and I should be applying the motion of the parent (platform) in my CharacterController.Move call going forward, or is this a bug?
     
    DevKragh likes this.
  2. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59
    Same problem here: 2019.1

    B) Fixed Update Platform - Normal Update Character Controller
    This seems to be the new solution now.
    Don't know why!
     
  3. deplorablemountaineer

    deplorablemountaineer

    Joined:
    Jun 16, 2018
    Posts:
    12
    I think the general solution is something like this.

    Say you have the Move calls in FixedUpdate.
    At the beginning of FixedUpdate, you have something like:

    Code (CSharp):
    1.             Vector3 externalMovement = transform.position - _savePosition;
    2.  
    where _savePosition is a global vector variable.

    Then, the call to Move has:
    Code (CSharp):
    1. cc.Move(extermanMovement + (the code you had before))
    Finally, at the end of FixedUpdate, you have:
    Code (CSharp):
    1.             _savePosition = transform.position;
    2.  
    In Awake or OnEnable or something, you'd need to initialize _savePosition to the starting position.

    Move, it seems, undoes the effect of changing the transform, so save the change, and do the move with the change added back in.

    Why does it matter if FixedUpdate vs Update is called? I suspect it's a race condition, has to do with the script execution order. In one order, the direct change to transform gets overwritten, in another order, it doesn't. And apparently I can't change CharacterController's execution order (unless I missed it scrolling through that long list), and I'm using a CinemachineDollyCart for my mover which won't let me change its order either (in the list, but grayed out).

    This is the result of me spending a few hours fiddling with this and googling for solutions to make platform riding work.