Search Unity

Is CharacterController now updated by FixedUpdate?

Discussion in 'Scripting' started by KazYamof, May 18, 2019.

  1. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59
    Using Unity 2019.1 There's no rigidbody in none of the objects. Character moves with CharacterController.Move method.

    MovingPlatform:
    Code (CSharp):
    1. Update() {  transform.Translate(transform.forward * speed * Time.deltaTime); }
    CharacterController:
    Code (CSharp):
    1. private void OnControllerColliderHit(ControllerColliderHit hit)
    2. {
    3.          if (charControl.isGrounded && hit.transform.tag == "Floor")
    4.                  transform.SetParent(hit.transform);
    5. }
    The character keeps sliding out the platform while standing fixed. Platform has the tag "Floor". The object is being setted as child while looking at hierarchy.

    Figured out that if I change the platform from Update to FixedUpdate, changing the parent of CharacterController will works, and it will be carried with the platform.

    FixedUpdate

    Code (CSharp):
    1. FixedUpdate() {transform.Translate (transform.forward * speed * Time.deltaTime); }
    But I can not say if it's a bug or a feature!
    So, it does not seem to be a 'answer', even if it works.

    Somebody else can confirm if there were some change in the CharacterController API causing SetParent to fail in this case?



    [EDIT 1]

    I also created a animated movind platform. I've noticed a strange behaviour, also related with update mode in the Animator component:

    Update mode: normal
    - When the character is over the platform, the platform moves and the character slides a little, but receive some motion from platform;

    Update mode: Animate Physics
    - When the character is over the platform, the platform moves carries the character, and the character is still able to move by onw his own.

    The documentation says:
    "Animate Physics The animator is updated in-sync with the FixedUpdate call (i.e. in lock-step with the physics system). You should use this mode if you are animating the motion of objects with physics interactions, such as characters which can push rigidbody
    objects around.

    -------------------------------------
    Animation.animatePhysics
    public bool animatePhysics;
    When turned on, animations will be executed in the physics loop. This is only useful in conjunction with kinematic rigidbodies.

    An animated platform can apply velocity and friction to rigid bodies sitting on top of it. In order to use this, animatePhysics must be enabled and animated object must be a kinematic rigid body."


    The main purpose of CharacterController isn't to be an alternative to Rigidbody?
    Why on earth do I need to program logic on FixedUpdate to get it working?
    The CharacterController is just an Kinematic Rigidbody?

    I'm serious, I need help to understand this!

    [EDIT 2]

    Attached a simple scene to test the behaviour
     

    Attached Files:

    Last edited: May 18, 2019
  2. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59