Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How to setup collision and triggers responses from single PhysicsShape?

Discussion in 'Physics for ECS' started by Elapotp, Aug 24, 2022.

  1. Elapotp

    Elapotp

    Joined:
    May 14, 2014
    Posts:
    98
    Hi, helpful community!

    I have a PlayerBody prefab with a single gameobject that has:
    — PhysicsBody component (set to Dynamic)
    — PhysicsShape component with Collide collision response.

    Also I have 2 types of game elements — Obstacles and HealthBoosters.
    Obstacles — Static.
    HealthBoosters — Kinematic.

    The idea is to collide with Obstacles and trigger HealthBoosters.
    1. Is it possible to have a setup with a single PhysicsShape on PlayerBody to collide and trigger?
    2. How to correctly assign CollisionFilter (should the player's collision filter set CollidesWith to HealthBooster value, or it is enough to have that on HealthBooster itself)?
    3. Will I get 2 collision events, if both of the collided entities are set to CollideRaiseCollisionEvents?
     
  2. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    271
    1. No, the dropdown only lets you select one. But you can have multiple physicsShapes on one entity (they are combined during conversion). Or you could opt to go for the Collide + Raise Collision Events and pickup the HealthBooster when the Player Body Collides with the Healthbooster. Edit: You would also get collision events from the obstacles in this case, you could filter them out by seeing if they have a HealthBoosterComponent or not.
    2. You need to set the BelongsTo and CollidesWith on both objects. So if the Player will belong to PlayerLayer and the HealthBooster belongs to ItemLayer. You need to set Player Collides with ItemLayer and also HealthBooster Collides With PlayerLayer.
    3. I don't think so, but let me know if I am wrong.

    Good luck
     
  3. Elapotp

    Elapotp

    Joined:
    May 14, 2014
    Posts:
    98
    Thank you, @Arnold_2013. Right now I ended up with 2 separate PhysicShapes on PlayerBody:
    1. For colliding with obstacles (based on Collide type)
    2. For triggering health boosters (based on RaiseTriggerEvents type)