Search Unity

Colliding two objects

Discussion in 'Scripting' started by schetty, Oct 12, 2012.

  1. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    Hi,

    I have a scene which is have the plane and above that one cube while running the scene i push the cube object that time its collide to the plane (cube go inside the plane). I have added the one more box collider to the plane but the problem is not solved.

    is there any other solutions to solve this issue?


    Thanks.
     
  2. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    144
    attach Rigidbody with Both Cube as well as with Plane.
    use this :

    function OnCollisionEnter (collision : Collision)
    {
    if (collision.gameObject.tag == "Cube")
    {

    Destroy (gameObject);
    }
    }


    Attach this script code with plane gameobject when both collide it destroy the plane.
    Hope this help.
     
  3. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    i have attached the rigidbody of both the object and another one i dont want to destroy the object, what i need is, when i apply the force to the cube it should not collide to the plane.
     
  4. Avo

    Avo

    Joined:
    Dec 4, 2010
    Posts:
    237
    If you want your cube to not collide with the plane you should turn off the planes collider. If no force is being applied to the cube it shouldn't be moving and therefore should not collide with the plane. What exactly are you trying to do?
     
  5. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    @Avo actually my plane and cube both have a collider and rigidbody. My plane collider iskinematic is true, at the runtime when i drag the cube it collide to the plane. i dont want to collide the cube to the plane. what should i do for that?
     
  6. Avo

    Avo

    Joined:
    Dec 4, 2010
    Posts:
    237
    Sorry, I'm having trouble understanding you. You want other objects to collide with the cube and other objects to collide with the plane but you don't want the cube and plane to collide?
     
  7. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    exactly..
     
  8. Avo

    Avo

    Joined:
    Dec 4, 2010
    Posts:
    237
    Alright, this is a multi step solution but it involves no code.

    1. Select your box, click the layer in the top right corner and select add layer from the bottom of the list. Name the layer something helpful.

    2. Go to Edit > Project settings > Physics Your inspector should change showing the universal physics for your scene. On the bottom of the screen there should be a triangle made out of check boxes.

    3. Uncheck the check box for the default layer for your new layer.

    I believe this should allow your cube to pass through your plane while remaining solid.
     
  9. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    ok i will try this..... let you know soon...
     
  10. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424

    sorry its not working is there any other way?
     
  11. Tanel

    Tanel

    Joined:
    Aug 31, 2011
    Posts:
    508
    Don't forget to assign the layer you created to your cube. And just in case check if the layer assigned to your plane is 'Default'.

    EDIT: Actually use the new layer for your plane too, because if you leave it at Default, the box won't collide with anything in the scene with that layer. So uncheck newLayer/newLayer in your physics settings.
     
    Last edited: Oct 12, 2012
  12. lightfoot218

    lightfoot218

    Joined:
    Nov 28, 2012
    Posts:
    2
    I think you need a box collider on the plane. If the volume of the collider is zero it won't collide.