Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question (Solved)transform.position != position on screen, while Rigidbody2D is moving. Why?

Discussion in 'Physics' started by tagimbul, Jan 11, 2022.

  1. tagimbul

    tagimbul

    Joined:
    Nov 17, 2016
    Posts:
    2
    In this picture you see a cross draw on transform.position while rigidbody2D is moving.
    But the cross draw ist not on the transform.position, its in a offset.
    help.PNG

    Why is that so?
    and how do I get the real position that you see on the screen?
     
    Last edited: Jan 11, 2022
  2. tagimbul

    tagimbul

    Joined:
    Nov 17, 2016
    Posts:
    2
    solved.
    i have change "Simulation Mode" in "Edit/Project Settings/ Physics 2D"
    from "Update" to "Fixed Update"
    now is transform.position on the real position

    help2.PNG
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,104
    Interpolation? The Rigidbody2D is the authority on the position, not the Transform. It's why it has Rigidbody2D.position and Rigidbody2D.rotation. If you use interpolation, per-frame the Transform is interpolated from the last position to the current position but that's for rendering. The body is at the correct physics position.

    If you set it to update per-frame then interpolation is turned off because you obviously don't need it.

    When using physics, especially queries, use the Rigidbody2D pose, not the Transform pose.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,104
    I don't understand how that would fix anything. I would understand if it were the other way around.