Cant get the Circle Collider on player to react when hitting the ground

im nto suyre what im doing wrong on this i feel like ive follow everything to a T. the last lecture just adding Debug.Log(“Ouch, i hit my head”); did not work. im not sure if my collider should be on a different object or what any help?


Hi,

First of all, add a Debug.Log to the OnTriggerEnter2D method. This will help you figure out whether this method gets called in the collision event. If it doesn’t get called, you don’t have to worry about the rest of the code inside the method code block because it will never get executed.

Secondly, the OnTriggerEnter2D method gets called only if a trigger collider is involved in the collision event. I assume that your ground has a “solid” collider, hence no trigger collider. And your screenshot does not show any trigger collider either. Did you mean to use the OnCollisionEnter2D method?


See also:

thank you for your response. I’m very new at this so I’m not sure. I’ve been trying to follow the tutorial to the letter. Rick uses an OnTriggerEnter2D and it seems to work for him. if i toggle the character to “Is Trigger” his head goes through the ground. when i changed it to “OnCollisionEnter2D” the code wouldn’t work at all. maybe my circle collider is on the wrong object?

i did get it working. changing it to “Is Trigger” did work i guess i just got caught up trying to figure out the code. sorry again very new at this still learning. thank you for your help.

No need to be sorry. I was a beginner, too, at some point. :slight_smile:

Actually, the head of Rick’s Barry should have dived into the ground instead of bouncing off. In later videos, you can see, that it doesn’t bounce anymore. Rick suspects that the surface effector made the head bounce in this case. Sometimes, there are undesired side-effects, and since we didn’t write the Collider2D classes or the surface effector class ourselves, we cannot prevent those side-effects.

You didn’t do anything wrong. The only “mistake” was the missing trigger collider. However, the trigger collider is a design decision. Rick could have achieved a bouncing head with a non-trigger collider but that would have been a bit more “difficult” because we have other non-trigger colliders. We want to make the player lose only if the head collider collides. This would require a bit more code.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms