My player head falls

Hello, I followed the course, and got a problem when the player fall on his head it falls in the ground, How can I fix this?

3 Likes

I haven’t done this course, but I think you have a collider that only sits on the board. You will probably need the collider to cover the character, too, to prevent his head from going through the ground

Hello,
I have the same problem, I also have a separate collider for the Head, when it’s not Triggered … well no “You Lost” shows up in console obviously but also the head doesn’t go through the ground.
Meanwhile when I check the ‘Is Triggered’ the message shows up but the collider doesn’t work.
Would you help please ?

1 Like

Hi @M2Cian! Welcome to the community

Here’s a simplified version of what is happening:

When two colliders overlap, the physics system updates the rigidbody to not continue moving in that direction. Very simplified, but that’s essentially what happens. However, when a collider is marked as a trigger, it is no longer considered a ‘physical’ thing. It only reports the collision, but the physics system does not do anything else with it.

So, when the collider on the head is not a trigger, the rigidbody detects the collision with the ground, and prevents the head from going through the ground, but when it is a trigger, it will go through the ground because the rigidbody is allowed to continue moving.

From your description it sounds like the game ends when the head hits the ground and it is marked as a trigger. We handle triggers in a OnTriggerEnter2D (or OnTriggerEnter for 3D games) method, but this will only get called if the collider is a trigger. If the collider is not a trigger, we have to instead handle OnCollisionEnter2D (or OnCollisionEnter for 3D games).

Hope this helps you out

Thank you,
I understand this but I’m using the exact code that Rick uses which is OnTriggerEnter2D and he has the head of the player Is Trigger and it works for him just like you explained.
I just don’t know why mine doesn’t work since I copied everything; same code, same settings :frowning:

I have the same issue - where the Debug.Log messege shows in screen for hitting ground with player head, but at the same time the player head goes under ground (Upside down position). I think the instructor changed something and didn’t show us.

Well there is an easy solution -

  1. Remove “CircleCollider” and “CrashDetector.cs” from Player gameObject and instead put them inside the child gameObject “Boarder_Top”.
  2. Make “is Trigger” False (Unchecked)
  3. In “CrashDetector.cs” script make it like this
using UnityEngine;

public class CrashDetector : MonoBehaviour
{
    private void OnCollisionEnter2D(Collision2D other) {
        Debug.Log("Ouch! I hit my head!");
    }
}

An the problem is solved !

2 Likes

@EZIOKITTU Welcome to the community!

@GameDev.tv As EZIO pointed out, OnCollisionEnter2D is a much better option here. Maybe Rick should annotate that when he has the time.

1 Like