Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collider Bounds Center Conundrum

Discussion in 'Editor & General Support' started by Quietus2, Dec 6, 2010.

  1. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    I'm attempting to calculate in code positions for hovercraft thrusters.

    Code (csharp):
    1.  
    2.  
    3. function Start() {
    4.  
    5.   frontThrusterPos = collider.bounds.center - Vector3(0, collider.bounds.extents.y, collider.bounds.extents.z);
    6.   rearThrusterPos = collider.bounds.center + Vector3(0, -collider.bounds.extents.y, collider.bounds.extents.z);
    7. }
    8.  
    This was working fine, up until suddenly Unity began giving bizarre values for the collider's center when starting the game.




    Here are the reported values in the inspector.



    Here is the debug print of the collider's center after starting the game.

    Any ideas? Never saw something like this before.
     
    Last edited: Dec 6, 2010
  2. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058


    Code (csharp):
    1. Gizmos.DrawWireSphere(transform.TransformPoint(collider.bounds.center), 0.1);
    I added a gizmo to display the world position of collider.bounds.center. It is indeed way off in the distance. /confused.
     
  3. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    It appears that collider.bounds is in world space not local space! Switching to mesh.bounds fixed it.

    Oops, RTFM.