What is the proper orientation for an overlapbox?
Hi there, after a good amount of searching I haven't been able to find out how to properly get the rotation of my overlap boxes set up.
I'm using it for damage calculation with a flamethrower. I have a trigger volume set up to map the size/coverage of the flamethrower's damage. Here's a little snippet for how I'm impementing it:
Collider[] hitColliders = Physics.OverlapBox(thisCollider.bounds.center, thisCollider.bounds.size, thisCollider.transform.rotation, layers);
for (int i = 0; i < hitColliders.Length; i++)
{
DamageCollider(hitColliders[i]);
}
Damage is being applied just fine (every 0.5 seconds it calls the above code) and when my rotation for the parent player gameobject is 0,0,0, everything is hunky dory.
I tried mapping out the actual hit area with a gizmo cube using the same variables as the overlap box call, but ran into a problem where the following issue occurs:
First, at 0,0,0 rotation, everything is fine.
But when it's rotated at all, it goes like this:
Does anyone have any idea why this might be? Am I giving the incorrect rotation for the call, or do overlapboxes not actually rotate how I expect them to?
Answer by GuardHei · Aug 19, 2018 at 12:08 PM
The bound of the collider is an AABB box which is perpendicular to the coordinate system and is the minimum enclosing box. The advantage of an AABB box is efficiency but losing accuracy at the same time. For the most of time, it is used for a primary filter.
For your problem, there are two ways I can think about. The first solution is the most accurate but costly. Use the collision module of the particle system. I won't give a complete tutorial here because that would be too long. It precisely calculates which flame particle hit what for each frame and of course, this leads to a low performance.
The second solution is to add a box collider or mesh collider to the flame object. Therefore, when the flame gets rotated, the collider will also rotate.