Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved other.transform.position wrong in OnTriggerEnter(Collider other) callback

Discussion in 'Physics' started by BrightBit, Feb 24, 2024.

  1. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Hi everyone,

    the red car in the following screenshot has a kinematic rigidbody and two convex mesh colliders set as triggers. I am pausing the editor via script as soon as the OnTriggerEnter callback fires.

    It then prints the world position of the upper most parent of the other collider (the blue car) but as you can see on the screenshot: The position is different to the position shown in the inspector.

    upload_2024-2-24_15-24-52.png

    Can anyone explain to me why that is?

    Thank you in advance for your help.
     
  2. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Of course. Just after I posted my question I came up with the thought that it might be related to the blue car's rigidbody interpolation mode and indeed: When I change it from "Interpolate" to "None" the positions match.

    However, that's definitely not what I want. Is there a way to get the interpolated position of the blue car's transform in an OnTriggerEnter event?
     
    Last edited: Feb 24, 2024
  3. BrightBit

    BrightBit

    Joined:
    Jan 22, 2013
    Posts:
    270
    Okay, I am an idiot: :)

    rigidbody.position will return the uninterpolated position
    rigidbody.transform.position will return the interpolated position (if interpolation was enabled on the Rigidbody)