Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

OnCollisionEnter not working

So basically my OnCollisionEnter doesn't seem to work, even though one of my colliders are a non-kinematic, non-static rigidbody .


Pls send help

Best Answer

  • lmc212006lmc212006 Member
    Accepted Answer

    I solved the problem!!

    All i had to do was update unity.

    But thanks for the help anyways :)

Answers

  • We need further info on that. What is trying to enter what, let us see the scripts and so on

  • MrSlugMrSlug Member

    As mentioned above, we do need a bit more information on this one.

    Out of curiosity, is the component that OnCollisionEnter isn't working on a CharacterController? If it is, try OnCollisionHit.

    Docs: https://docs.unity3d.com/ScriptReference/ControllerColliderHit.html

  • @MrSlug it is a rigidbody based character controller

  • lmc212006lmc212006 Member
    edited May 2020

    @MrSlug i will try using OnCollisionHit tomorrow


    @joachim747 the script is as follows:

    using UnityEngine;


    public class Obstacle:MonoBehavior

    {

    void OnCollisionEnter()

    {

    Debug.Log("Hit");

    }

    }

  • MrSlugMrSlug Member
    edited May 2020

    One thing to note, when using OnCollisionEnter it should take an argument of Collision collision so you can gather some information on what you collided with, take a look:

    https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

  • WarpWarp Administrator

    Send us some screenshots of your components/objects.

    I remember reading somewhere in the manual that not all collider types actually invoke OnCollisionEnter, and they had a table for it.

    Its somewhere in here, I read through it a while ago, so I dont know exactly where it is.

    Take a read through it, its good material.

    Best of luck!

  • lmc212006lmc212006 Member
    edited May 2020

    @MrSlug i have already tried adding a Collision to the function, sadly it doesn't seem to work :(


    @Warp here is the screenshot of my components:


  • Can you do this to debug you collider?

    void OnCollisionEnter(Collider other) {

    Debug.Log(other.name);

    }


    Make sure it collides with other objects that also have colliders. This script has to be attached to your current GameObject where you want to detect the collisions.

  • WarpWarp Administrator

    Can we get a screenshot of the inspector you are colliding with, and not receiving data from? We need both screenshots of the player, and the thing you're trying to collide with.

    Try @ShidyGames suggestion aswell, its good advice.

  • @ShidyGames Im afraid I have already tried that...

    @Warp I can't give you the screenshot of the other collider today, but i will share it tomorrow if that is fine by you


    Again thanks for all this help

Sign In or Register to comment.