- Home /
Be on a cube and be collided with that cube you are on.
Hello.
My quesiton is quite simple, i would like to make things like that :
I am on the ground (Plane). When i go on a cube (cube) which is Y = 0,1, i would like the Player enters in collision with the Cube, because it's the case..
I already checked theses functions :
void OnCollisionStay(Collision collision) {
foreach (ContactPoint contact in collision.contacts) {
...
}
}
and
void OnTriggerEnter(Collider col) {
if(col.gameObject.tag == "Player"){
...
}
}
But none works ...
Can anybody explain me how does the contacts are made ? And by the way, a solution for my problem.
Thanks
look whether you checked is trigger on the box collider.
Answer by fafase · Apr 08, 2012 at 05:49 PM
OnTriggerEnter is used if you want to get through the object.You tick IsTrigger on the collider. For example you want to have a zone in the game that trigger something(a gui will show up for example or launching an animation), you use this one because you don't want to bump into an invisible shape. Simply put trigger are ignored by the physic engine
OnCollisionEnter is used when you want to keep the interaction between the two colliders. Without IsTrigger and this function you check collision and only a tiny part of the bounding volume actually interacts (not enough to be seen).
Now if you want to stay on the box, just add a box collider to it. If your guy has a character controller he will stay on top of it.
You can check collision with OnControllerColliderHit
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnControllerColliderHit.html
Answer by ExTheSea · Apr 08, 2012 at 05:53 PM
Is your collider you refer to in the second example a trigger? If it's not you can't access it through OnTriggerEnter.
So you should check IsTrigger on the box collider if it isn't already.