Trigger isn't working consistently

Hello, so I have a player and when he enters the trigger he is supposed to respawn and lose a life which as you can see happens at the start of the the video. But for some reason when failing off the side closer to the trigger’s edge it doesn’t seem to work for some reason. Debug.Log that I wrote to let me know if the players enters the trigger isn’t run. But the player clearly touches the collider.

Video to better explain the problem:

As you can see the trigger works when falling close to the middle of it but not when the player falls near the edge of it.

My Scirpt:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerLivesManager : MonoBehaviour
{
    private void OnTriggerEnter(Collider collision)
    {
       
        if(collision.gameObject.tag == "Player")
        {
            Debug.Log("Player entered collider");
            PlayerInput playerInput = collision.GetComponentInChildren<PlayerInput>();
            Lives lives = collision.gameObject.GetComponent<Lives>();
            lives.playerLives--;

            if(lives.playerLives == 0)
            {
               
                GameManager.instnace.PlayerLeft(collision.gameObject);
                GameManager.instnace.playerList.Remove(playerInput);
                Destroy(collision.gameObject);
               
            }
           
            collision.gameObject.transform.position = GameManager.instnace.spawnPoints[0].transform.position;
        }
    }
}

Responses to common questions that might be asked:
The player does have a RigidBody
The Box Collider’s “Is Trigger” is checked as true
The Player doesn have a BoxCollider component

This is my first time posting a question on here so excuse me if I broke any Posting Guideline, let me know.

What sort of collider does the Player have? Have you tried increasing the Y size of the trigger collider just in case the player is passing by the collider in a single frame period?

The player has a Box Collider and the Y size of the trigger is 1.2 so it’s plenty tall I don’t think that’s the problem, otherwise it wouldn’t work when the player falls in the middle ass well

To get an OnTriggerEnter() message, the following must be true:

  • either object needs an OnTriggerEnter() method
  • both objects need a collider, and one needs to be .isTrigger = true
  • one of the objects needs a Rigidbody which is NOT .isKinematic = true
  • the layers of the two Collider objects must intersect in the Physics settings Layer Matrix
    (or a special call to IgnoreCollision must be made to override the Layer Matrix)

For the object(s) which have Rigidbody, colliders can be in child objects and the message is ALSO sent to the Rigidbody parent to let you centralize handling.

Try one of the following:
Do a Debug.Log in your OnTrigger() method (I see you already did that)
Check if all of the object in the context have a collider
Check if the colliders are not despawning/disabling because of a script
make sure there is a rigidbody which is not kinematic.
Also make sure your dementions of the trigger are correct, trust me it happens a lot

hope this helps :slight_smile:
have a great day

All of these are true but it still doesn’t work. I mean you can see in the video it works there is only 1 box collider, but it only works when the player is near the center of it not near the sides. Watch the video again please.

All of these are true but it still doesn’t work. Could it be that Unity bugged out?

Thats wierd. I might try to re-create it but I am working on a game rn, I will try my best tho.

I’m not convinced of this. Looks like the player hits an invisible collider on the first attempt. Disable everything in your scene except the player and the collider and test again.

You don’t seem to understand. There is only 1 collider. The player hits this collider on the first attempt as you say. And he should also hit it on the second attempt as well but he doesn’t for some reason that is the problem. The collider only seems to be working when the player is close to the center of it.

9778428--1401981--upload_2024-4-18_14-24-19.png

You says there’s only one collider, but there’s clearly multiple colliders in your scene. I can tell the player is hitting a collider next to the platform on the first attempt. And how would the player stay on the platform if there was no collider on the platform?

I mean there is only one collider in the area where the player falls, not one collider in the entire Scene, sorry for the confusion

Sorry if this is a dumb question, but is the object that you have selected in the screenshots the one that has the PlayerLivesManager script? I don’t see that in the list of components.

It’s the white plane under the blue arena

Right, but is the PlayerLivesManager actually attached to that object? It does not show up in the inspector in your screenshots.

Oh sorry if you mean the PlayerLivesmanager that’s on a GameManager gameobject

If PlayerLivesManager is only on the GameManager, then the OnTriggerEnter code is only going to trigger when the player hits a collider on the GameManager object itself. If you want this to run when the player hits the trigger attached to the Cube object, then the script needs to be attached to the Cube object you are using for the floor.