- Home /
World scale of BoxCollider for Raycast and scale
Hey, I'm trying to do something rather specific and awkward, and I'm find it to be a lot of trouble. I have a BoxCollider, which is attached to a sort of "feeler" object on the player. The collider is used to detect collisions with other players, but what I also want to do is cast a ray along the length of the collider, and then resize the object to fit within the available space. Everything seems to work fine so far, the only thing that's really left is getting the length of the BoxCollider to do the Raycast. I just cannot for the life of me find a way to do it. The collider is arbitrarily rotated, which makes things a bit more awkward. Bounds.extents is useless, as the collider is not a cube, and itgives a point well outside the collider. Casting to a BoxCollider and using size will give me the values I gave to the scale, but I can't seem to push those into world scale, as Transform.TransformDirection gives me a value that is incredibly far off. I just cannot seem to find a way to do this, and I'm completely out of ideas. If anyone has any suggestions as to how to get the actual size of a BoxCollider, I would be really grateful to hear it...
Answer by Owen-Reynolds · Jul 12, 2013 at 10:57 PM
One standard trick is to child an empty to the end of your collider, facing (blue/Z) which ever way you plan to shoot.
It will move/rotate with your collider and model. Then just use transform.Find("theCollider/endEmpty");
to locate and use it. It you do any odd scaling, etc... you can pause and check if it's still in the correct spot/facing.
Wonderful suggestion that didn't even cross my $$anonymous$$d. I eventually found that, while TransformDirection didn't work, simply manually multiplying by the localScale vectors did. Still, I'll accept your answer because it is both valid and efficient, and should work in the majority of circumstances.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110014im_/https://answers.unity.com/themes/thub/images/avi.jpg)