Search Unity

How to change the orientation for an overlapbox?

Discussion in 'Physics' started by Norvegat147, Sep 16, 2019.

  1. Norvegat147


    Nov 5, 2016
    Hi there, after a good amount of searching I haven't been able to find out how to change the rotation of my overlap boxes set up.
    Code (CSharp):
    1. //draw a hitbox in front of the character to see which objects it collides with
    2. Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * lastAttack.collDistance;
    3. Vector3 boxSize = new Vector3 (lastAttack.CollSize/2, lastAttack.CollSize/2, hitZRange/2);
    4. Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, transform.rotation, HitLayerMask);
    I'm using it for damage calculation. I want the OverlapBox to take the same rotation of the player and always be in front of the player.