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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

CharacterController Question

Discussion in 'Scripting' started by mjzx, Jul 30, 2018.

  1. mjzx

    mjzx

    Joined:
    Aug 18, 2013
    Posts:
    114
    Hello, sorry if this is a stupid question, and sorry if it's in the wrong section of the forum.
    I was taking a look at this link:
    https://docs.unity3d.com/ScriptReference/CharacterController.Move.html
    And in the example there is this:
    Code (CSharp):
    1. moveDirection.y -= gravity * Time.deltaTime;
    2. controller.Move(moveDirection * Time.deltaTime);
    Is this some kind of mistake? Why would the gravity need to be multiplied by Time.deltaTime, when the result is multiplied by it anyway? That would make the gravity be multiplied by Time.deltaTime^2, which seems incorrect to me.

    Any clarification on this would be appreciated.
    Cheers.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    Interesting. Never used it. But I think, this may suppose to be like:

    Code (CSharp):
    1.  
    2. moveDirection *= Time.deltaTime ;
    3. moveDirection.y -= gravity * Time.deltaTime;
    4. controller.Move ( moveDirection );
    5.  
    That would make more sense to me.

    Which in fact is
    Code (CSharp):
    1.  
    2. moveDirection.y -= gravity;
    3. controller.Move ( moveDirection * Time.deltaTime );
    4.  
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Yeah, it's probably a typo.

    Docs are often outdated. If in doubt - test it.
     
  4. teutonicus

    teutonicus

    Joined:
    Jul 4, 2012
    Posts:
    67
    Looks right to me; gravity's an acceleration (m/s^2) and CharacterController::Move takes absolute movement delta, not a velocity.
     
  5. mjzx

    mjzx

    Joined:
    Aug 18, 2013
    Posts:
    114
    Okay, good to see some people agree with me.
    Hmm, interesting... That seems correct. I was wondering if that was the case.
    Would you be able to explain the term 'absolute movement delta'? Sorry, it just doesn't really make sense to me ;)
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    I think he means simply an acceleration. as delta of velocity, is acceleration. Similar delta of position is, is velocity. Where delta is a change, or difference.

    While m/s^2 makes sens indeed and I was also thinking about it, it is badly presented in documentation.
     
    Last edited: Jul 31, 2018