Search Unity

Physics Engine Colliders as Triggers or Manual Collision Detection?

Discussion in 'Physics' started by paulg5682, Feb 11, 2019.

  1. paulg5682

    paulg5682

    Joined:
    Feb 14, 2016
    Posts:
    11
    This is for an action rpg where you might be swarmed with mobs. So there will potentially be a lot of intersections/collision detections.

    If I want to do hit detection at specific frames, is it better to do your own 3D intersection calculation or to use the unity built in physics colliders with trigger events?


    For the most part, the collisions will be in the xy plane and then just check the z height of an object.

    I have read a few posts and see arguments for both.

    Is it more costly to use the physics engine to check for collisions or more costly to do my own collision detection for oriented bounding boxes, spheres, arcs, and cylinders?

    Pros/Cons for manual:
    pros
    1. I need arc collision detection (pie wedge shape doesn't exist in unity)
    2. I can perform calculations on specific sets of objects
    3. I can filter out specific sets of monsters based on distance
    4. Physics intersections are not calculated on frames they are not needed

    cons
    1. manually implements collision detection


    Pros/Cons for unity physics:
    pros
    1. most cases are handled for me, I don't need to reimplement OBB/Sphere/Cylinder collision detection
    2. I can limit collision detection between groups of objects with the layers system
    3. I can turn off colliders on objects that are out of screen view

    cons
    1. It seems I have to enable colliders before the frame I need to check the intersection so unity physics can send the proper OnTriggerEnter/Stay/Exit events
    2. Arc collision detection will be manually calculated

    I just don't know which way to go though? Thoughts?

    Thanks,

    Paul
     
  2. paulg5682

    paulg5682

    Joined:
    Feb 14, 2016
    Posts:
    11
    I solved my problem.

    I did not realize there was a Physics.OverlapBox. I kept trying to use Physics.BoxCast.
    I can also use the Physics.OverlapSphere and then perform the dot product check for my specific angle. This allows me to not have colliders for attack hit box.