Hey guys, just a pretty simple question, do all triggers need to have a rigidbody? Say you have non-moving invisible trigger that when the player steps on it, opens a door. Would I need to give this object a rigidbody/kinematic rigidbody?
No, this object doesnât need a rigidbody. Only the player should have a rigidbody.
Okay, could you explain this for me also, from the unity manual: Even when immobile, kinematic rigidbody colliders have different behavior to static colliders. For example, if the collider is set to as a trigger then you also need to add a rigidbody to it in order to receive trigger events in your script. If you donât want the trigger to fall under gravity or otherwise be affected by physics then you can set the IsKinematic property on its rigidbody.
Okay, could you explain this for me also, from the unity manual: Even when immobile, kinematic rigidbody colliders have different behavior to static colliders. For example, if the collider is set to as a trigger then you also need to add a rigidbody to it in order to receive trigger events in your script. If you donât want the trigger to fall under gravity or otherwise be affected by physics then you can set the IsKinematic property on its rigidbody.
Just make it easier for me to understand what this is saying.
Several parts of the manual regarding colliders and rigidbodies are outdated and come from the Unity 5 era. As for today, static colliders raise trigger events when any other rigidbody (either kinematic or not) contacts them.
For example, I use static colliders (without rigidodies) in racing tracks for detecting shortcuts. Each collider is marked as Trigger and includes a script that listens to the OnTriggerEnter event. Works flawlessly:
So just to clarify, you put the OnTriggerEvent script inside the actual trigger itself, and if it detects an object with a tag of âracecarâ then it will react to it and do something?
And I am just caught up on that sentence above (âeven when immobile, kinematic colliders are different to staticâŚâ) that I donât understand. Are you telling me that sentence is outdated or something. If itâs not could you explain it to me word for word cause the wording in the sentence is just confusing.
Yes, Iâve put a script in the same GameObject as the trigger itself. The script contains a method âOnTriggerEnterâ. This method is called whenever any Rigidbody touches the trigger. The method receives the information of the colliding object, so you can take your decisions based on the tag or any other property.
Are you seeing the correct documentation? I canât find anything like that in the Unity docs. Maybe youâre reading the docs for a (very) past version of Unity:
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
The docs are accurate afaik: One of the entities is required to have a Rigidbody. Itâs simply a matter of where you put it. Do you want it on the trigger? the other? both? Does anyone care? You decide.
If you have a niche case regarding kinematics/statics then you should clarify the conditions and give an example of something that is not working.
This sentence is confusing though cause it sounds like itâs saying that all triggers need to have a rigid body. The wording in the sentence is kind of confusing and I donât know what itâs trying to say, Iâm just a beginner. I just want to know what this means in really simple terms.
Yes, it is in the kinematic rigidbody collider section in the second paragraph: https://docs.unity3d.com/Manual/CollidersOverview.html
Oh, ok. That information requires an update. It doesnât mention that you can make kinematic colliders interact seamlessly with other colliders with the Contact Pairs Mode option in the Physics settings:
I always configure âEnable All Contact Pairsâ in my projects so kinematic bodies work the same way as non-kinematic ones.
What is confusing? It seems fairly straightforward to me - simply one of the Colliders involved has to have a Rigidbody also.
If you have an overlapping pair of colliders then at least one of them must have a Rigidbody to activate the collision and trigger events as needed for everyone involved. Consider a bunch of buildings in a city. They donât need rigidbodies because the active rigidbodies moving around during gameplay are going to be the ones âtriggeringâ events when they are needed. Are you not seeing this be true in your tests?
It feels to me like this is saying that if you have a collider thatâs a trigger, then you also need to add a rigidbody to it, but thatâs not always true. I donât really understand the example itâs giving and I also donât understand how immobile kinematic rigidbodies are different than static colliders. Could you explain it super simple and easy of a word for word of the sentence I donât understand. Sorry I donât get it, Iâm still learning.
Is it just saying that if you have a trigger then somewhere in the equation there needs to be a rigid body?
Forget that information. Itâs incomplete (see my post above).
Super-simple:
- Open Project Settings > Physics. Configure âContact Pairs Modeâ to âEnable All Contact Pairsâ.
- Add Rigidbodies to the physically moving objects only.
- Use static triggers, static colliders, OnTriggerEnter, etc normally. Any project, any platform (desktop, mobile, etc)
How exactly are immobile kinematic rigidbody colliders different than static colliders?
Edy is more familiar with the technicals, but I can explain what I know
Static colliders are supposed to be things that never move. You flag them as static and expect it to never change. This lets some calculations process them faster because it knows they shouldnât ever be moving. An example would be a bunch of buildings, or props, or terrain.
Kinematic is just a Rigidbody that does not receive forces. An example would be a character that you control explicitly and donât want other forces interfering. Drop a kinematic box into a pile of non-kinematic boxes and it will plow them completely out of the way no matter what their mass is. If itâs âimmobileâ, I assume you mean itâs just not moving. In that case, itâs just a Rigidbody that isnât moving and isnât going to be moved by random forces hitting it. Pretty simple.
So the sentence above that I was so confused on is wrong. Because not all triggers need rigidbodies to receive trigger events, yet it still says "For example, if the collider is set to as a trigger then you also need to add a rigidbody to it in order to receive trigger events in your script". Sorry if Iâm wrong but thatâs what Iâve been so confused about.
Itâs not really the colliding Iâm worried about but I get what youâre saying. Tell me though, if this option was not enabled and not possible to change, what is this sentence trying to say?