Problems with private void OnCollisionEnter (Collision collision)

(Perdón por mi inglés, soy español)

Hello, I was making a videogame for slenderman with all their respective codes until when my slenderman touches my character it doesn’t detect it with the panelend or gameover with textpro instead if it works for the house (cabin) that is integrated with private void OnTriggerEnter( Collider other), but unlike Slenderman using private void OnCollisionEnter(Collision collision) once the player is touched nothing happens and I would like to know if something is missing or what to add because I can’t find it.

Points to consider:
-the RigidBodyFPSController is labeled “Player”
-Slenderman uses navmesh to chase the player.
-The house(cabin) with “private void OnTriggerEnter(Collider other)” works with a collider once it is already in place.
-The player is being used with rigidbody.
-The panelend should work for both slenderman and the cabin, however when the slenderman touches the player it is not detected.
-I have no problems on the console.

my problem “guide” (video):

I’ll leave screenshots and codes here.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class SlenderMan : MonoBehaviour
{

    private Transform objetivo;
    private NavMeshAgent agente;
    private GameManager gameManager;



    private void Awake()
    {
        objetivo = GameObject.FindGameObjectWithTag("Player").transform;
        agente = GetComponent<NavMeshAgent>();
        gameManager = FindObjectOfType<GameManager>();
    }
   private void Start()
    {
        StartCoroutine(tiempoDestruccion());
    }

    private void Update()
    {
        agente.SetDestination(objetivo.position);

    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            gameManager.Aparecefinal("Has Muerto");
        }
    }

    private IEnumerator tiempoDestruccion()
    {
        for (int i = 0; i < 15; i++)
        {
            yield return new WaitForSeconds(1);
        }
        gameManager.CrearNuevoSlender();
        Destroy(this.gameObject);
    }

}

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

public class Casa : MonoBehaviour
{
[SerializeField] GameManager gameManager;

private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag(“Player”))
{
gameManager.Aparecefinal(“A salvo”);
}
}
}


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

public class GameManager : MonoBehaviour
{
[SerializeField] GameObject slender;
[SerializeField] GameObject personaje;
[SerializeField] Transform[ ] arrayPuntosSalida;
[SerializeField] GameObject panelFinal;
[SerializeField] private TextMeshProUGUI textoFinal;

private int puntoSalida;

private void Start()
{
EstablecerPunto(personaje);
CrearNuevoSlender();
}

private void EstablecerPunto(GameObject objeto)
{
puntoSalida = Random.Range(0, arrayPuntosSalida.Length);
objeto.transform.position = arrayPuntosSalida[puntoSalida].position;
}

public void CrearNuevoSlender()
{
Instantiate(slender);
EstablecerPunto(slender);
}

public void Botones(bool eleccion)
{
if (eleccion == true)
{
SceneManager.LoadScene(0);
}
else
{
Application.Quit();
}
}

public void Aparecefinal(string texto)
{
panelFinal.SetActive(true);
textoFinal.text = texto;

}
}





Should be (Collision collision). The type name begins with C mayúscula

@kdgalla i tried but it didn’t work for the script slenderman :frowning:

If your code is not working (and there are no error messages in the console) then the next thing to do would be to use a lot of Debug.Log statements to see what is going on. For example you can put something like Debug.Log("collision happened"); inside of the OnCollisionEnter to see if Unity detects collision. If you see the message in the console, that means that OnCollisionEnter executed. If you don’t see it, that means Unity did not detect the collision.

If Unity is detecting the collision and the code still doesn’t work, try Debug.Log("other object tag: "+collision.gameObject.tag);[/ICODE] to see if the object that’s colliding is what you think it is.

Hmm… for some reason it doesn’t detect it when they collide since the message doesn’t appear on the console the “debug.log”, Is there another alternative apart from using oncollisionenter? i plan to do a gameover scene change when the slenderman touches it

How did you get this far in your game without knowing how OnCollisionEnter works, without knowing how to debug and with what seems any knowledge on how to make a game?

Is this code you presented your code? I doubt it.

I don’t have much knowledge in scripts, but I try to solve it

Looks like some generic asset(s).

OnCollision is probably the best and easiest method to use. Do Slenderman and the player both have colliders? Be sure they are not set to “trigger”

@kdgalla For OnCollisionEnter, they both have Colliders (plus they need them to collide with trees). None have the “Istrigger” marked.

Update, @kdgalla

I managed to solve the problem, it turns out that my collider capsule was not in the slender “variant” along with the code, my collider capsule was under the slenderman which is another object, that’s why I didn’t detect it along with the code.

In short, my collider capsule all this time was not together with the code in Slender “Variant” but on the other hand it was not.

1 Like