- Home /
Can't First person Controller's children have collision?
Hi,
I've a scene with a first person controller who, at same point, has to pick up and grab an object (namely, a pickaxe). I've solved this part creating a child object of the fps controller, initially disabled with this.gameObject.active = false;
and when necessary enabling it with the same method.
The problem is that the character should use this pickaxe to destroy some in-game object. I was thinking to use some methods like function OnCollisionEnter(collision : Collision) { if (collision.gameObject.tag == "ThingToDestroy") { Destroy(collision.gameObject);
}
}
but I can't manage in any way to give a collider to the pickaxe, as long as it's a child of the fps controller, so collisions can't be triggered by that object. If the pickaxe isn't a controller's child, it gains immediately the collider. Is this a bug, or is there a reason, and a way to get things working as I want? Thanks for the assistance!
Answer by Owen-Reynolds · Mar 09, 2012 at 08:08 PM
If your guy is using a CharacterController, then it partially overrides child colliders.
What happens is, a charController does its own movement math based on the capsule. Any extra colliders it has are just rammed through solid objects. They still trigger CollisionEnter (not 100% sure...,) and other things still bounce off of them, but when they try to tell the parent charController about not having any room to go there, it ignores them.
It's a giant pain to switch to non-charController movement (and in popular RPGs your sword is always going through walls anyway -- they use charController style.) For most hitting and picking up, you don't worry too much about an actual collision. If you're facing the rock, just animate the axe swing and add +1 quartz.
Thanks for the answer! The fact the pickaxe goes though object isn't a real problem; the big issue is that I need to destroy the object it hits, and OnCollisionEnter doesn't seem to work in this case! Is there a workaround, or another method to do what I want?
Answer by peppe · Mar 10, 2012 at 12:08 PM
Nevermind, I've found a good solution in this thread: http://answers.unity3d.com/questions/29781/first-person-melee-system-how-to-attach-a-weapon-w.html
Kudos to the original poster!
If you are ever able to, give them a "thumb check" of appreciation.
Also, to keep things easy to read, try to make "Answers" be answers. This one is fine -- it's an answer to your Q. The other one would look nicer as a comment on my "answer."
Unfortunately, I can't (yet) properly thank either that post or yours, so I can just express a verbal appreciation. Sorry for posting inappropriately, it has been the first time I've used this board - now my post should be in order...