- Home /
[CLOSED] FPC's childrens can't have collisions?
Eh.... Next question and next waiting for answer :P. OK, I've got a small problem. I add some children to First Person Controller. These childrens have colliders, but they are doesn't work when the objects are childrens of FPC. How to solve this problem?
Photo for Gruffy:
For collisions I tried this:
OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Hook") // The Hook is one of FPC childrens
{
Debug.Log("Hook collider works fine. Collision detected.");
}
}
I'm sure that this code works, because I use it many times, but note that I tried to use "OnTriggerEnter" too. I attach this script to object in the scene and collide Hook with it, but Console is doesn't show my message. Hook is the children of First Person Controller and it has box collider attached to it.
Answer by Gruffy · Mar 29, 2014 at 04:03 PM
OKay, so firstly, you need to put a box collider or whatever collider type you wish on your hook. You say thats already done, so does it look like this... ![Image OF collider with "isTrigger"][1]
If so, does it have you script attached to detect collisions?
If yes to that, then do the gameobjects you fish for have colliders attached to them?
If yes to the above, do those gameobjects also have rigidbodys with "isKinematic" checked and "Use Gravity" unchecked attached to them.
If so, from here and in the script you have attached to your hook game object that should be detecting a collision as such, Place this in to your script and remove any other methods that were trying to do this before.
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Fish")
{
Debug.Log("Fish Triggered Hook");
}
}
void OnTriggerStay(Collider col)
{
if(col.gameObject.tag == "Fish")
{
Debug.Log("Fish still at hook");
}
}
void OnTriggerExit(Collider col)
{
if(col.gameObject.tag == "Fish")
{
Debug.Log("Fish left Hook");
}
}
Finally, you NEED to go to your game object fishy and ass the Tag "Fish" to them and make sure each one or your prefab has it in its Tag slot at the top of gameobject`s inspector. [1]: /storage/temp/24485-unity-answers.png
Your answer
Follow this Question
Related Questions
Collider causes terrible lags 1 Answer
First Person Controller not working with OnCollisionEnter and OnTriggerEnter 1 Answer
Player walks through everthing 0 Answers
FirstPersonCharacter 1 Answer