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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to extend rigidbody bounds

Discussion in 'Scripting' started by Ardmark, Oct 24, 2012.

  1. Ardmark

    Ardmark

    Joined:
    Oct 24, 2012
    Posts:
    11
    Hi,

    I am trying to increase the bounds of a rigidbody collider, but nothing seems to work. I've tried the following in Start() :
    Code (csharp):
    1.     for (int i=0;i<10;i++)
    2.     {
    3.                 GameObject go = m_gameObjects[i];
    4.     MeshRenderer mr = go.GetComponent<MeshRenderer>();
    5.     Mesh mesh = mr.GetComponent<MeshFilter>().mesh;
    6.     mesh.bounds.Expand (new Vector3(1f, 1f, 1f));
    7.     go.rigidbody.collider.bounds.SetMinMax(new Vector3(-1f,-1f,-1f), new Vector3(1f,1f,1f));
    8.     go.rigidbody.collider.bounds.Expand(new Vector3(1f, 1f, 1f));
    9.     }
    - but when I run the game the rigid bodies still collide as if they are still tightly wrapped to the visible mesh.
    This looks like it should be a no-brainer, so what am I doing wrong?
    Thanks.
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
  3. Ardmark

    Ardmark

    Joined:
    Oct 24, 2012
    Posts:
    11
    That's fixed it.
    Now looking at the docs, I can see Expand() and SetMinMax() are not inherited methods in BoxCollider, which would explain why using them on the parent rigidbody.collider object would not work. Anyway, that's solved a big problem for me. Thanks!
     
  4. jay-jin

    jay-jin

    Joined:
    Jun 22, 2014
    Posts:
    12
    Very helpful,I waste a lot of time on this!
    collider.bounds.Expand(....)