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?
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 ?
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
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 -
- Remove âCircleColliderâ and âCrashDetector.csâ from Player gameObject and instead put them inside the child gameObject âBoarder_Topâ.
- Make âis Triggerâ False (Unchecked)
- 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 !
@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.