Tag not working when head hits ground

Yes, exactly. The head in Rick’s game is a trigger collider, which is not supposed to bounce off. For some unknown reason, it does bounce. We suspect that this effect might have been caused by the SurfaceEffector2D component even though it was not supposed to happen.

If you prefer a bouncing head, you could disable “Is Trigger” in the Collider2D component. In that case, you must not use OnTriggerEnter2D, though, but OnCollisionEnter2D. OnTriggerEnter2D gets called only if one of the two colliders in the current collision event is a trigger collider.

It might also make sense to keep the CrashDetector script on the head game object, so Barry’s snowboard collider will not call this method as well.

However, if you found an alternative solution that’s perfectly fine. In many cases, there are multiple ways to make something work in Unity.

Does your game work now as expected? :slight_smile:


See also:

This is making a little more sense now, thank you! Yes, I was able to wrap up the snowboard game finally! I would love to figure out how add a sliding SFX when the board touches the ground. I tried three different ideas i had in the script but no luck. For now, moving on to the quiz game. But, I will definitely revisit the Snowboard game when i get a better understanding of the whole process. Been a blast so far, even cried once, lol

Thanks guys!

I do not know what you’ve already tried but the problem with the current setup is the following: The snowboard collider moves on/above the edge collider. Each bump causes it to “exit” that edge collider.

To figure out if that’s a problem, you could call the OnCollisionStay2D or OnCollisionExit2D method to do what you want to do. Displaying particles should not be difficult. Just call the Play() method on the particle system and call Stop() if you want to stop the emission.

If the situation I described in the first paragraph causes unpleasant results, you could create a new collider: this time, a trigger collider. That trigger collider should be below the snowboard collider. The edge collider of the ground should be inside that trigger collider. Make it large enough so it does not exit the edge collider just because there was a tiny bump. Of course, you will have to use the OnTrigger* methods here instead of the OnCollision* methods.

No worries if this sounds too confusing or difficult. After you completed this course, you should have enough knowledge to make at least this idea work. The main problem is not the code itself but “Unity”. You cannot expect too much precision in the physics simulation, so you will have to fake certain things to achieve nice results. Your future players will just see the result. For this reason, it is perfectly fine to implement solutions that would not work in the real world. :slight_smile:

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

Privacy & Terms