Inner Mesh BoxCollider

When we add a BoxCollider, it's auto-adjusts out of the mesh (outer bounds).
How to create a BoxCollider inner the mesh? Automatically or via script
Answer by streeetwalker · Jun 11, 2020 at 06:07 PM
@vlab22, have you tried changing the size and center vectors in the box collider inspector?
Sorry, I didn't explain that I want an automatic solution.
@vlab22 There is no 'automatic solution". Are you talking about doing this at runtime, or in the editor?
Either way, you'd have to code one in, and do to that then you have to be able to define what an automatic solution would look like. How much smaller and where within the mesh do you want it centered? You'd have to be able to generalize parameters you need to create an automatic solution.
@vlab22, to continue - you can access a gameObject's boxCollider component, and then use the alter size and center vectors. for example
// drag your game object to the inspector field to get a reference
public GameObject gO;
void Start() {
BoxCollider bC = gO.GetComponent<BoxCollider>();
bC.size = new Vector3( 1f, 0.5f, 2f );
// and so on with the center property of the collider
}
Your answer
Follow this Question
Related Questions
My Click and drag object moves slowly after I drop it 0 Answers
Up Down Game , Player Enemy / Walls [Box Collider] 1 Answer
Is it better to use the Plane Mesh Collider or a Box Collider for Walls and Floors. 1 Answer
Physics.BoxCastAll incorrect results 0 Answers
GameObject to follow player but constraint in a box 1 Answer