Hello again Unity3D users and game developers!
First thing I would like to say explaining my situation is that I have been reading about collision detection in Unity3D for several hours. And many of the questions that were posted on the Unity Answers community have already been read once or twice by me now. Please reference all you want, it won't hurt or anything, but don't make that hold you back from attempting to answer yourself please!
OnTriggerEnter seems to evaluate specifically tagged objects ( Unwanted , since I don't feel like tagging 8976216 level items , nor nag the non-programmers here to do so, probably a nice idea for switches but not for floors and walls)
OnCollisionEnter seems to check for interaction with other colliders and rigidbodies.
Currently there are some holes in the whole collision detection system for me. Before I go and learn the collision detection matrix scroll down in link from A-Z, I want to be able to understand the following question:
WHO is calling WHAT, WHEN?
Should I get a controller or rigidbody instantiation inside my script to check what's going on when I want to know if the parent is standing on the floor or bumped his/her head?
Everyone is just mashing the following aswell I noticed
"Unfortunatly in JS"
Ok the event is raised somehow? Why build a method with the same name unless it is an override of something inside the UnityEngine imported library or overload for that matter? I can't seem to find any references in any object or library to such methods so I would assume it's homemade. If so, who calls it then, nothing in all the code samples is? Everyone keeps replying to these methods with "It does not work" aswell, so I'm not the only person bugged by this I'm guessing.
All the collision detection methods and events seem really usefull and practical, but not when I can't for the life of me figure how who's controlling them when and how. Even my components in the game never heard of them. (EDIT 4/13/2011 , this is actually good programming practice, the functions within the library only need to know what to do , not where the live or what their neighbours are doing , aka, encapsulation)
Eventually I want to be able to check collisions with the environment from inside the player object using my controller script, without having to tag the entire the world, and WITH at least a basic understanding of what is going on under the hood.
I tested the following
I have tested colliding with my character with an RB (RigidBody) attached to collide with all permutations with rigidbodies colliders ( not caring about the shape or size) . All no effect
The results were interesting. Only OnControllerColliderHit actually ever responded. If they were functions called like Update and Start, then they should have responded. So am I missing something in the code or whatnot ? I copy pasted straight from the unity scripting reference C# example btw.
Apperantly the OnControllerColliderHit only checks if a collision just occured, it will not work as a work around for the slightly more advanced collision detection I need in my product. So I will be needing a bit of help getting the OnTrigger and OnCollision calls done somehow.
EDIT 11/15/2010 (2):
Got just the trigger event working, still nothing on the other 3 though.
The controlling instance for everything collision related is the physics engine. The engine will call all those collision/trigger functions when it detects a collision. It will call these functions on all gameObjects that are part of a collision. The OnControllerColliderHit function is an overridable function just as Update or Start. To see a list of all those functions look at the scripting docs under MonoBehaviour.
Also it is wrong that you need to tag anything for OnTriggerEnter to happen. It's just common practice to tag certain objects, to have a fast way to determine if you've hit something relevant or just the ground for example.
To see when which method is called you can look at the mentioned collision matrix. In short: A collision happens if at least one of the two "colliding" objects is a dynamic rigidbody and both have some sort of collider (not trigger) attached to them. A trigger event will happen when one of the two objects is a rigidbody (dynamic or kinematic) and both have colliders attached and one of those is a trigger.
answered Nov 10, 2010 at 12:19 PM