Search Unity

BoxCollider doesn't collide with Plane..

Discussion in 'Scripting' started by giancamati, Nov 10, 2010.

  1. giancamati

    giancamati

    Joined:
    Aug 4, 2010
    Posts:
    518
    Hello everybody,

    I have my mesh and I attached to it a BoxCollider and set its bounds in this way:

    Bounds bnd = obj.GetComponent<MeshFilter>().mesh.bounds; obj.GetComponent<BoxCollider>().size = bnd.extents;

    where obj is a GameObject with a RigidBody and a BoxCollider. So, in the scene there is a plane with a BoxCollider too....
    As soon as I run the application, the object falls onto the plane and goes through and no collision is generated. The object keeps falling ...:(

    what am I doing wrong?

    GC.
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    I coded this in javascript, though its pretty simple to translate it back. I believe that this is what you are searching for. I dont know why your messing with the bounds of the mesh.

    That being said, you should be useing bnd.size, not bnd. extents.

    Description
    The extents of the box. This is always half of the size.

    Code (csharp):
    1.  
    2. function Start(){
    3.     transform.gameObject.AddComponent(Rigidbody);
    4.     rigidbody.mass=1000;
    5.     transform.gameObject.AddComponent(BoxCollider);
    6. }
    7.  
    8.