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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Rigidbody.MovePosition

Discussion in 'Physics' started by pmourao, Aug 31, 2023.

  1. pmourao

    pmourao

    Joined:
    Jul 25, 2021
    Posts:
    4
    Hello, I have a question regarding Rigidbody.MovePosition:

    Example from UnityDocumentation - Version 2022.3:
    void FixedUpdate()
    {
    //Apply the movement vector to the current position, which is
    //multiplied by deltaTime and speed for a smooth MovePosition
    m_Rigidbody.MovePosition(transform.position + m_Input * Time.deltaTime * m_Speed);
    }

    Question: what would be more appropriate, Time.deltaTime, as in the example above, or Time.fixedDeltaTime, as in UnityDocumentation 2019.4?
    Another question: would be correct, instead of "transform.position + m_Input", to use "m_Rigidbody.position + m_Input"?

    Thank you for your attention, any comments are welcome.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,438
    Time.deltaTime is more appropriate. When used inside a FixedUpdate method, it returns Time.fixedDeltaTime.

    About the second question, using Rigidbody.position is more correct than Transform.position. For example, if rigidbody interpolation is enabled, the physical position (Rigidbody.position) will differ from the visual position (Transform.position).
     
    LouveniaWard, pmourao and MelvMay like this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,756
    Just agreeing with what @Edy just said.
     
    pmourao and Edy like this.
  4. pmourao

    pmourao

    Joined:
    Jul 25, 2021
    Posts:
    4
    Hi @Edy and @MelvMay
    It's more clear to me now.
    Thanks for the help!
     
    MelvMay likes this.
  5. LouveniaWard

    LouveniaWard

    Joined:
    Sep 14, 2023
    Posts:
    1
    Thank you, I appreciate you.
     
    Last edited: Sep 21, 2023