Reputation: 586
I have got two objects:
Object A (SteamVR Camera):
Object B (Globe model):
I made sure that the collider ranges are correctly, but somehow the OnCollisionEnter method does not get triggered.
The code that I am using for OnCollisionEnter looks like below:
private void OnCollisionEnter(Collision collision)
{
Debug.Log("Collision entered");
}
Could someone provide me some insight/advice?
Thanks in forward.
Upvotes: 1
Views: 9471
Reputation: 2408
To understand how collision works you need first to identify which objects are colliding, because very few objects may trigger OnCollisionEnter.
From your description we can identify 2 types of objects.
Object A: Kinematic Rigidbody Trigger Collider
Object B: Static Trigger Collider
If you check the Collision Matrix there could be no collision with anything that has a Trigger (both Object A and Object B), so OnCollisionEnter won't fire.
I repeat: a Trigger does not collide with anything no matter what the other object is.
If you want to get the event from a collision with a trigger objects (or 2 of them, like in your case) you can use OnTriggerEnter.
Consider that in this case the parameter of the method will be Collider other
that is a Collider instead of a Collision, but in your case I think you won't need the collision at all.
private void OnTriggerEnter(Collider other)
=> Debug.Log("entered");
The collisions depend on the rigidbody and collider setup objects. I can show a few examples based on your situation.
The first element to consider is that Static Collider is not an usual Object set as Static (this was a source of confusion in the comments below).
From Unity Manual
STATIC COLLIDER
This is a GameObject that has a Collider but no Rigidbody. Static colliders are used for level geometry which always stays at the same place and never moves around. Incoming rigidbody objects will collide with the static collider but will not move it.
Consider also that you want to use a trigger (that makes your STATIC COLLDER into a STATIC TRIGGER COLLIDER).
Basically the idea behind trigger is: "Use triggers when you want to catch the event but you don't want the gameobject interacting with Physics forces."
The scripting system can detect when collisions occur and initiate actions using the OnCollisionEnter function. However, you can also use the physics engine simply to detect when one collider enters the space of another without creating a collision. A collider configured as a Trigger (using the Is Trigger property) does not behave as a solid object and will simply allow other colliders to pass through. When a collider enters its space, a trigger will call the OnTriggerEnter function on the trigger object’s scripts
Upvotes: 5