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

Question Rigidbody with multiple colliders in different layers.

Discussion in 'Physics' started by dkennedy69, May 20, 2023.

  1. dkennedy69

    dkennedy69

    Joined:
    Jan 22, 2017
    Posts:
    3
    Hello. Looking for some advice how to deal with a rigidbody with 2 colliders in different layers.

    I have 2 layers for obstacle objects in my project: "Obstacles" itself collides with game actors and also weapon projectiles. "ObstaclesDecorative" collides only with actors, i.e. prevents moving but doesn't blocks the LOS and we can aim and shoot trough it with some firearms. So, i have the "lower" obstacles in the "ObstaclesDecorative" layer and "higher" ones (walls, barricades and so on) in the "true" obctacles layer.

    So, I'm trying to make some pickup car with the cabin acting as an "Obstacle" and the trunk - as a "ObstacleDecorative". So we can shoot trough it, place some boxes or enemies in the trunk and so on.

    So the pickup prefab consists of 2 parts (the cabin and the trunk) as it shown in the pics related.

    Each part has a boxcollider. The parental gameobject has a rigidbody that intended to handle both of the colliders and make this vehicle pushable by the player (or an AI actor).
    The problem is: seems the Rigidbody can't handle both of the colliders if they are set in different layers. The actor can't push the pickup in this configuration (if I set both parts of the car in "Obstacles" layer, it works).

    I've tryed to make some composite collider in the parental gameobj (and check the proper box in my colliders ofc) but it doesn't help.

    Have read the unity documentation about rigidbody, barely helped.

    So I'm looking for a way to make the Rigidbody handle 2 colliders in 2 different layers or some another way to acheive the described behaviour (we can shoot trough the trunk but we also can push the car's rigidbody). Maybe I don't understand some basics, dunno... Will appreciate for any ideas.
    Spent some time googling and chatGPTing it, found no answer :))
     

    Attached Files:

  2. dkennedy69

    dkennedy69

    Joined:
    Jan 22, 2017
    Posts:
    3
    Resolved: made 2 different RBs for each part of the car, connected them with a joint.