AddBoxCollider creates a collider that's too small

The box collider that’s created by AddBoxCollider method is too small. How do I change the size of it? it needs to be as big as the enemy.

 private void AddBoxCollider()
    {
        Collider boxCollider = gameObject.AddComponent<BoxCollider>();
        boxCollider.isTrigger = false;
        
    }

Hi,

Could you share a screenshot, please? What scale does the parent game object have?

The scale of each enemy is 3.5, 3.5, 3.5.



For the screenshot below, I experimented with boxCollider.transform.localscale(5,5,5) which is why it says 5,5,5 on the ship.

That probably did not work because there is no MeshRenderer assigned to the same game object to which the code assigns the box collider.

For simplicity, I would suggest to remove that line of code and add a collider manually.

Ok, but why can I see the enemy ship even though there’s no mesh renderer on it?

Because your child game objects have got Mesh Renderer components with meshes assigned.

Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms