Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Applying force to just one of two colliding objects

Discussion in 'Physics' started by Lukazos, May 2, 2019.

  1. Lukazos

    Lukazos

    Joined:
    Jan 11, 2018
    Posts:
    5
    So here's the deal. We are creating a game where you play as a giant and destroy houses. The houses are split into pieces when they interact with the giant and it works for the most part. But I want the giant to run smoothly through the houses which don't really work due to so many rigidbodies colliding. Is there a way to make the giant not interact with the house pieces but the pieces interact with the giant? Kinda like a one-sided collision.

    I've tried making the difference in mass as big as possible but to no real effect.
    Also tried this: https://forum.unity.com/threads/ignore-force-from-certain-rigidbodies.505973/#post-3299112
    but again, no real difference.

    A video showing what it looks like when they collide at the moment.
    https://drive.google.com/file/d/1kcSTkW7udHcEdX4iCFbdyNXt0eAVwtCi/view?usp=sharing
     
  2. srivello

    srivello

    Joined:
    Jan 16, 2011
    Posts:
    16
    Good question.

    I don't know enough about your problem to know if your solution will be adequate, but I can answer your question.

    If you want object 'a' to collide with object 'b' but not vice versa you can use layers. Add a to layer a and b to layer b, then in the project settings UNCHECK that b collides with a.

    https://docs.unity3d.com/Manual/LayerBasedCollision.html

     
  3. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    723
    I don't think selective collisions will help on its own-- we still need the building pieces to collide with the giant, and there is no way to turn off one "side" of the collision with the collision matrix. Physics.IgnoreCollision is a similar story.

    The manual mentions that large mass differences may cause some instability. What mass values did you try? Did you experiment with a lot of different values, or only extreme values?

    Something you might try is to pair the Collider's on the body parts with kinematic Rigidbody's. If you can't make them kinematic because they need to be able to be influenced by other things, then you could add a set of subchildren to each body part, each with another Collider and a kinematic Rigidbody whose only purpose is to knock stuff down. Assign layers and define the collision matrix so that these will interact with only buildings, and turn off collision with buildings for the first set, and collisions between the two sets. This may lead to other complexities, but I think it should be manageable.

    Hopefully there isn't something more obvious that I'm not considering.
     
    Lukazos likes this.
  4. Lukazos

    Lukazos

    Joined:
    Jan 11, 2018
    Posts:
    5
    Thank you for the Answers. I managed to solve it on my own using some trickery with layers. I basically made the giants own collider not interact with the house pieces, then I created new colliders as children of the giant and just set the position of those to the different parts of the giant. This created the desired effect. Hope this can work as a possible solution for others in the future.
     

    Attached Files: