I think I know the answer, but the docs aren’t clear enough for me.
If I have BoxCollider as a component of a GameObject and I scale the GameObject by changing localScale, THEN set BoxCollider.size, is the result affected by the GameObject’s scale?
GameObject scale is 0.1, 0.5, 0.1
BoxCollider.size = new Vector3(0.5, 0.5, 0.5); // expecting a square box
When I look at the properties in Unity, I see: 0.05, 0.25, 0.05.
It’s basically following the shape of the GameObject.
Any way around this?
Thanks!
I am using a simple cylinder primitive as a child of the GameObject. I also tried putting the BoxCollider in the Cylinder instead of the GameObject, same results.
I tired scaling the values I put into the BoxCollider.size using the inverse of the GameObject.scale, but that lead to the BoxCollider.size being half what I expected it to be.
Very frustrating!
Are you resetting the box collider to the size of the child object before you scale, by right clicking on the gear in the top right corner of the box col component. Then run you game scaling the child and the box collider should stay with it. Most the time it’s not necessary to scale the box collider unless there is a special reason for it.
What are you trying to create?
Why does the box collider need to be scaled by code instead of just automatically scaling with the child Obj?
Thanks 4 the reply.
When I reset it does follow the size.
Thanks again!