- Home /
Trigger between 2 kinematic bodies not firing?
I seem to be unable to get a trigger to fire between to objects.
resetTrigger = GameObject.CreatePrimitive(PrimitiveType.Cube);
Rigidbody rb = resetTrigger.AddComponent<Rigidbody>();
rb.collider.enabled = true;
rb.collider.isTrigger = true;
resetTrigger.name = reset_trigger_name;
resetTrigger.transform.localScale = new Vector3(5f, 600f, 5f);
resetTrigger.transform.position = new Vector3(0, 0, -500f);
resetTrigger.collider.enabled = true;
resetTrigger.collider.isTrigger = true;
resetTrigger.renderer.enabled = true;
resetTrigger prt = resetTrigger.AddComponent<resetTrigger>();
prt.manager = this;
prt.playerTransform = player;
The other object is a prefab with a rigid body attached to it directly, as well as having 2 rigid body objects in the prefab.
There is a script attached to the prefab directly, which has both a box collider and rigidbodt, that looks for the OnTriggerEnter() event that is never fired.
If I look at OnTriggerEnter() on the other object, it does fire.
Is there something about prefabs I don't quite know?
A prefab is not in the scene. What do you mean, that you have two objects, one which is a prefab you dragged into the scene and one which is not?
Have you double checked that the colliders are triggers and that your GameObjects are on the same layer or at least, on layers that will collide - check your physics settings.
Also note that even objects with Is$$anonymous$$inematic ticked and gravity not ticked will not trigger without some movement.
I have since changed the way it operates so that this is no longer an issue, although I did like this solution more and intend to revisit it.
If I remember correctly, from what I was seeing, the OnTriggerEnter() was only firing on the object in motion, rather than the object that was stationary.
Basically, I had an EmptyGameObject that contained 2 instantiations of a prefab. This EmptyGameObject also had a BoxCollider (trigger) attached to it that wrapped both of the instantiated prefabs. I was trying to get OnTriggerEnter() to fire in the script attached to the EmptyGameObject.
Obviously I'm aware triggers work perfectly . I was simply doing something incorrect, or not allowed. Or perhaps the OnTrigger does only fire on the object in motion.
I'll come up with another solution if that's the case.