Parented Game object with collider not colliding

Hi, I have a 1st person player, using character controller.
I have some walls.
The Player colliders and wont go through the walls.
GREAT SO FAR!
The player can “pick up” and electric guitar. This is an game object with a box collider on it. Hovering over it picks it up, which means its position is placed right in front of the view, and is parented to the camera, so that it moves with you.

HOWEVER! When I move towards a wall, the guitar will go through the wall, the player will stop, but as you move around the guitar will intersect the wall.

How can I stop this from happening?

When something is parented it pulls all of it’s locational data from the parent object. This will override things like collisions.

One way to fix your issue would be to add an additional collider to the parent object that is at the location of the guitar object. Then it will not let the guitar pass through the wall.

There are multiple ways to tackle this. The simplest way might be to not have the guitar become a child of the character controller at all, instead have it’s transform position constantly updating to be at a position of an empty or invisible game object.

Another way to do it would be to create a collider that is the same shape, size, and orientation of the guitar’s collider on the parent object when the guitar get’s picked up.

@Static Dynamo said

You can actually create a collider
that has its center is offset from the
position of the object that you have
the collider attached to.
Yes but the character controller doesnt ACTUALLY rotate itself so when the camera rortaes AROUND the char controller, the child object will stay where it was.

This will mimic the behavior of a child object
that is offset from the parent without
needing to do any child/parent
relationship. So it can still work
even if you have a mouselook script
moving the camera around, because the
collider attached to the camera is
offset from the camera’s transform
position.

And that collider WILL rotate around the char controller WITH the camera. So still not convinced by this, (or not getting it) Does this pic (whiteboard equivalent) help?

Maybe not?

:slight_smile:

Mark