Kill boundaries not working when they should

I got working enemies but when I have the tag and trigger on a box with no collision below the map, it just does not work. I will send some screenshots if they are needed of the box but the box really should work.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class KillFloor : MonoBehaviour
{
    [SerializeField] private Transform player;
    [SerializeField] private Transform respawn_point;

    bool dead;



    private Rigidbody playerRigidbody;

    public int lifesAmount;

    int lifesLeft, lifesLost;

    private void Awake()
    {
        lifesLeft = lifesAmount;
        dead = false;
    }

    private void Start()
    {
       

        playerRigidbody = player.GetComponent<Rigidbody>();
        
    }

    private void OnTriggerEnter(Collider other)
    {
       

        if (other.gameObject.CompareTag("Enemy"))
        {

            float distance = Vector3.Distance(player.position, other.transform.position);
            if (distance < 4f)

                if (playerRigidbody != null)
            {
                
                playerRigidbody.position = respawn_point.position;
                playerRigidbody.velocity = Vector3.zero; // Reset velocity to avoid unwanted movement
                lifesLeft--;
                lifesLost++;
                dead = true;
                Debug.Log("Dead=true");
            }
            else
            {
               
                player.transform.position = respawn_point.position;
                lifesLeft--;
                lifesLost++;
                dead = true;
                Debug.Log("Dead=true");
            }

            Debug.Log("Collided" + other.gameObject.CompareTag("Enemy"));
            Debug.Log("Collided 2" + gameObject.name);


            StartCoroutine(ResetDead());
        }

    }

    private void Update()
    {
        Input();
    }

    private void Input()
    {



        if (dead == true && lifesLeft < 0)
        {
            Debug.Log("Died");
            Killed();
        }
    }

    private void Killed()
    {
        SceneManager.LoadScene("Menu");
    }

    private IEnumerator ResetDead()
    {
        yield return new WaitForSeconds(1f);

        if (lifesLeft > 0)
        {
            dead = false;
            Debug.Log("Dead=false");
        }
    }
}

First step to debugging is to make sure the script is even running.

Then see what you’re being called with trigger-wise, if anything.

Check also that you are meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

That is not even close to being related to what I posted.

Are you using an OnTrigger* function?

Are you expecting that to do the job you’re complaining isn’t happening?

Then what I posted is related.

Good luck!

I have debugged extensively, it works with everything else except the kill barriers. So don’t bother trying to go “OoH BoOT DbOUging Wofdrks” I have checked so now I am asking here. If you do not want to help, just don’t send anything, thank you.

Triggers need colliders to work.

The minimum requirements for OnTrigger and similar to work are clearly spelled out in the docs: Unity - Scripting API: Collider.OnTriggerEnter(Collider)

Debugging includes referring to the docs to ensure you are using the system correctly.

Please don’t be an ass to others trying to help. You’ve not explained what steps you’ve taken to debug the problem so it’s of course relevant.

I have an exhaustive troubleshooting resource you can go through:

@shadvault32 If so, maybe layers? Did you check on which layers are this killer barriers (check in physics settings). And can this layer affect object with this script?

Hope it this above, and your devlife will be easier now. Let us know!

Yes, I have made sure of it, it should work but doesn’t. By no collision, I meant it has a trigger collision but will not actually stop me from falling through it, it used to work before I modified the script to work as a lives counter, nothing about the trigger has changed.

It is the same layer as the enemies I have in my game.

I have debugged extensively, that is why I am asking here.

You’ll need to add a rigidbody to the box.

I have tried that already, sorry.

Just so you know before you waste too much more of your time waiting…

There is no evil cabal of people here who know the answer to your problem and are choosing not to tell you.

We do not know what the problem is in your project. That’s not a thing we know.

The problem is in your project and YOU (or someone sitting at your project) is going to need to figure it out.

We’ve given you the tools again and again and you’ve insisted things like,

The way you will know you have “debugged extensively” is when come in here and list the small handful of steps ( I think its 5 or 6 steps) required to receive trigger collision messages and prove you did each one and describe what is and isn’t happening.

The list of those steps is in the documentation for physics, specifically detecting trigger collisions. If you can’t get it from there, you certainly won’t get it from a bunch of random yahoos like me retyping parts of it for you in this box.

So again, as a reminder:

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

When you are still baffled, here is…

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

You never tell us what debugging steps you’ve done so it’s very hard for us to make suggestions.

My troubleshooting resource for this problem is exhaustive (linked in the post you replied to), if there’s a problem that’s not listed there that stops physics messages I want to know about it. As others have pointed out, saying you’ve debugged extensively is completely meaningless.

I guess I will just make a new script for this, I have debugged this for so long I could have written a working script 3 times over for this. I guess that will be more simple that trying to fix it.

The script above looks perfect. That’s why nobody here has suggested you change it.

Scripts are a teeny tiny tiny micro nearly irrelevant step of getting a trigger to give you a callback.

As stated multiple times above, there’s a checklist in the docs of all the things you need.

Those things are DO NOT GO in a script. They just don’t. Full stop.

If you miss even one of those things listed in the physics collider / trigger documentation, all the scripts in the entire world will not make it work.

We have also suggested adding debug statements to it so you can find out if it’s getting called or not, before you check for the tag.

Again, you have got to find out what is wrong before you can fix it.

I am saying that I will make a new script specialized just for the kill barriers.