- Home /
How to move BoxCollider2D
Hi, I want to move a BoxCollider2D to a certain Position relative to my Player, but whenever I use something like: BoxCollider2D.transform.position it moves the player and not the collider. I'm using a Non-kinematic rigidbody aswell if that helps. P.S. I am aware that BoxCollider2D.transform.position is for the GameObject related to the boxcollider, I need to know how to move the BoxCollider2D.
Answer by tanoshimi · Mar 01, 2015 at 07:59 PM
BoxCollider2D is a component. Transform is also a component.
So, BoxCollider2D has no "position" of its own - only the position of the transform component on the GameObject to which it is attached. If you want to create a collider that can be placed at a different location than the mesh renderer (which is the component that lets you see where an object is), you need to place the box collider on a separate child GameObject.