I have an object that has a collider on it which is a trigger. When the player enters the trigger, the object becomes a child of the player and the player carries it to another place where the object is placed, becoming the child of a third object. As it is being carried, it goes through walls and such which doesn’t look good, so I added “collider.isTrigger = false;” to the script hoping that would prevent it doing that. Well, it still goes through walls but now it is slowing the player down and somehow getting in the player’s way even though it is a child of the player.
Any ideas how to rectify this?
I think you need to set the collider’s attachedRigidbody to the rigidbody in question.
What moves the player? If it is a character controller you should expand it to surround both the player and object. If it is a rigidbody, you will have to first make the collider a child of the rigidbody, set it’s isTrigger to false and then destroy and immediately recreate the rigidbody component.
This is due to a bug where setting attachedRigidbody on the collider doesn’t actually work.
Hmm. It’s a character controller but the object is being carried a little ways in front of the player and if I expand the controller to include that then the player will be too wide to fit through tunnels and doors… What I don’t get is why the player bumps into it when it’s a child of the player and yet the object doesn’t bump into walls.
are both the object and walls mesh colliders?
Thanks for responding. The wall has a mesh collider; the key has a box collider.
I have been playing with this a lot and changed things around quite a bit. Now, the object’s collider is not a trigger and as soon as it becomes a child of the player, the player can’t move anywhere. I didn’t think a child object would get in the way of a player like that. When the object had its collider as a trigger the player could carry it around fine (but it went through walls) but now it can’t carry it at all.
What I want to do is pick up and carry an object that will bump into things.
I’ve tried several different approaches with no luck yet…
Actually, to be more clear, while the player can’t go anywhere, he can turn around with the oject turning around with him. So the object is not fixed in place and moves with him when he turns but somehow does not let him move. Very weird to me…
i had a very similar problem while trying to modify the grab gun script on some other post to make it possible for me to carry around rigid bodes, for some reason if a child object is a rigid body, it will not move with my player, however it will still orbit around it, which i dont understand. so i wound up just removing the rigid body of the objects when i picked them up, and then i had the exact same problem as you, it went through walls and other objects andl ooked really sloppy, i still have no solution for this because it seams very important to be able to parent rigid bodys to other objects. i dont see why this dosent happen
but from what i understand, your problem is that the child object prevents your player from moving at all??
Hmm. So it’s not just something I am doing that’s weird, then.
My player can rotate but not move back and forth at all after “picking up” the object (the object is actually offset a little so that it is sticking into the player’s capsule as that looks better from the player’s POV).
Does anyone know how to have players carry objects that bump into things but don’t trip up the player??
I’m still playing around with this hoping to find some way to fix it so I can finally get my game done. I have tried something new. I added a box to the player that is a child of the player from the very beginning. I was hoping I could have the collider turned off until I pick up my object and then turn it on when the object gets picked up. However, I get the same problem as before. With my player having this object it will not move around! Turn yes - move back and forth or side to side, no. What gives?! Can a player not have a child object with a collider?? I am using the regular FPSWalker script… If someone could help me, either letting me know this is normal behavior and I have to live with it or that it’s not and I must be doing something wrong, I’d be really grateful.
What is happening is that the character controller is running into the collider and thus stops.
You could move the collider further in front, turn it into a trigger if that makes sense for your case or switch to a rigidbody based controller instead.
It would be useful to have some context as to why you need a collider hanging in front of the character.
Thanks for your response. The reason is so that when the player carries an object the object does not go through walls. I don’t understand though why the player would run into the collider when the collider is a child object - shouldn’t the children be moving together with the parent?
So this is similar to the player carrying a gun which might intersect with the level geometry.
Even if it was possible with the character controller to have colliders as children making the capsule into some sort of compound collider, it would not be what you want. Because it would actually prevent you from rotating, if you are looking at a wall. This is practically never what you want in a game.
The way this problem is usually solved with guns is:
- Make the player capsule larger and move the graphical picked up object closer to the camera
- Make the graphical object smaller than it actually is and move it closer to the camera. Thus it looks like it is just as big but wont intersect with level geometry.
I presume this is for a first person camera?
While this seems like a hack at first, it is one of those things where it is better to come up with a solution that feels better (always being able to rotate) than being physically correct.
OK. Thank you! I don’t need things to be physically correct at all and making a little object close to the camera sounds like a great workaround. I’ll go do it.
Thanks again.
you can also have a second camera render the gun in front of everything else.
Thats possible and its easier to do.
But you have to clear depth and especially on older graphics cards, clearing the depth buffer is not for free. Its not a big hit, but i think its easy enough to avoid with the other two techniques.