What is it you’re trying to do? Attaching a rigidbody that is marked IsKinematic is essentially the same as having no rigidbody, except you do get these messages. Is there a particular reason you don’t want a rigidbody attached?
I just tested it, and the other colliding objects must have a rigidbody or it wont work. I don’t even need one on my trigger object, but putting one on does no good…
In order for trigger messages to be sent, one of the colliders has to have a rigidbody attached. The rigidbody can be kinematic. As Sam mentioned this is essentially the same as having a collider without rigidbody. So this is always a possibility.
However you seem to have a rigidbody or character controller already on the player. In that case you do not need a rigidbody on the trigger.
So your setup is as it is supposed to be. Do you have the the script that contains on trigger enter attached to the player rigidbody? Or how exactly is your setup?
Thats not the case. If that was unclear in the docs, i would love to hear where that is.
I have a box with a box collider. I extended the Z size of the box collider to 10 and checked the isTrigger value. I also attached a rigidbody to the same cude and checked Is Kinematic.
I have another tall cube that just has a collider on it and no rigidbody. This cube is animated to pass through the trigger area of my other cube.
If you move a Collider around that contains the trigger then you might run into sleeping issues. This is why it is recommended to use kinematic rigidbodies on colliders that move around alot. If you don’t actually want to move the Collider around, then you dont need that.
Sorry Joe, I am a bit dense tonight and I don’t quite understand. :shock:
I am doing code for obstacle avoidance, and I can’t have the obstacles have rigidbodies as they will be generated automatically.
I want to project a box trigger in front on my agents and use that to detect possible collisions.
My problem is, when I have my trigger contact a non-rigidbody controller, the OnTriggerEnter() event doesn’t get called even if I have a rigidbody on my agent.
As for the sleeping issues with kinematic rbs, would you mind explaining that again?
Thaks a for the help, please pardon my denseness
-Jeremy
EDIT: I also unchecked isKinematic on my trigger object to see if it made a difference. It didn’t.
If the agent has a collider instead of a trigger, does it properly described? The way it sounds makes me wonder if the colliding object actually has a collider on it…
Nope, unless the object passing through the trigger or collider has a rigidbody, no messages are sent.
If it makes any difference, the script with the OnTriggerEnter() function is attached to my trigger object, as that is the object that actually needs the information.
If you move the trigger collider around in your scene it NEEDS to have a kinematic rigidbody attached to it. If you do not, and the other rigididbody has fallen asleep, it will pass through it, without getting the call.
The general rule is if you have a collider which you move around, add a kinematic rigidbody.
Even if you build the game object from code you can always add a kinematic rigidbody.
A kinematic rigidbody moving around in the scene.
A static collider which is set to be a trigger, which is NOT being moved.
The script is attached to the static collider.
I get the OnTriggerEnter call as expected, when the kinematic rigidbody passes through the trigger.
www.otee.dk/joe/trigger.zip
If you can’t get your setup to work somehow, send me a small project folder and i will take a look.
Joe, your setup works fine, but what I need to do is a little different.
I can’t put rigidbodies on the objects that are supposed to collide with the trigger because of the level design.
I can only attach a rigidbody to my trigger object itself and that doesn’t work. It only works if the object colliding with my trigger has a rigidbody and I can’t do that.
EDIT: To do what I am trying with your example, take the rigidbody component off your moving object, and put it on the trigger object.
I can’t imagine any situation where you can’t put a kinematic rigidbody on a collider. What exactly is your use case and why do you think you can’t put kinematic rigidbodies on the moving objects?
The other objects are going to be terrain objects that are generated automatically. So that’s why I can’t put rigidbodies on them.
My problem is; why can’t I just have a rigidbody on the trigger object? Why do the objects colliding with the trigger need rigidbodies and is there any way around that? Is this a bug?
If you have a collider which you move around, then you need to have a kinematic rigidbody on it. If you don’t intent to move a collier around you don’t need the rigidbody / kinematic rigidbody on it.
From what i understand your setup is like this:
You have static colliders which never moves. They are set to be normal colliders (not triggers). You have scripts attached to the collider.
You have a kinematic rigidbody with a box collider trigger attached. This object you move around.
If this is your setup, it should work. I just modified the project folder i made yesterday to test that exact setup and it does work. So most likely it’s a script attached to the wrong object or something. If you can’t figure it out, feel free to send in the project folder and i’ll take a look.