My main question is: is it possible to put OnTriggerEnter in a script that goes attached to the moving character instead of to trigger area/object? Let me explain my exact need.

I want to detect the collision between an object called MyCube and another called MyOther, but without MyOther stopping MyCube to go on. It is, MyCube should not be stopped or bounced. It should actually just move on, without any physics reaction. Yes, I know that it can be achieved by using Triggers.

More specifically, I should define MyOther's bounding box as a Trigger and then define MyCube as a kinematic rigidbody. Then, I should add a script to MyOther with a function like, for instance, OnTriggerEnter. However, in my scene I will have thousands of objects like MyOther, i.e. working as triggers, and also all the action to be performed when colliding would be performed on the movign character itself. So I would like to retrieve the collision not trough MyOther, but trough MyCube.

1) I thought that I could put OnTriggerEnter in a script attached to the moving character, but when I do that no collision is recognized. No trigging occurs. Is such a thing possible?

2) Otherwise, is there another way trough which I could achieve what I have described?

  • \$\begingroup\$ Here is a good collision matrix and explanation. Also notice "Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below." \$\endgroup\$ – Exerion Oct 8 '15 at 5:54
  • \$\begingroup\$ Thanks for your comment, @Exerion. But I mentioned that one of them, the moving character, is a kinematic Rigidbody. And also, the examples in that doc page say exactly what I describe I already know: how to set Triggers the usual way (with Trigger messages at the MyOther, in my example). Unfortunatelly, there is no word there about the specific case I ask for \$\endgroup\$ – Louis15 Oct 8 '15 at 6:05
  • \$\begingroup\$ in one of my games the ball moves and collides with blocks. At some point I need to make it 'ghost'-like to go through blocks, but still detect collisions/triggers. I've just enable/disable isTrigger from a script and it works fine. Never saw your problem using same setting. When I get back from work, I will open that project, look and comment, if I'll find something. \$\endgroup\$ – Exerion Oct 8 '15 at 6:45
  • \$\begingroup\$ @Exerion thanks, I'd appreciate that! Let me just ask: IsTrigger is set to ball or to the blocks? Because my problem is precisely that I want to have the OnTriggerEnter at moving character (in your case the ball), not at each of the thousand static colliders (in your case the blocks) I have. I does work if I put these Trigger events on the static colliders, what does not work is if the moving object (like the ball) is the trigger and has OnTriggerEnter. \$\endgroup\$ – Louis15 Oct 8 '15 at 7:07
  • \$\begingroup\$ yes, isTrigger is set to a ball. As I remember, while I was trying to implement this, I wrote both methods OnTriggerEnter and OnCollisionEnter in a Ball's script and added a simple debugging messages to the console. Since blocks have non-trigger collider, they may invoke OnColliderEnter method in script attached to 'other', different from the block gameobject (in this case - the ball). You can try to implement both methods in your moving character. \$\endgroup\$ – Exerion Oct 8 '15 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.