RunOverPickup not working with character controller

I am using this code:

    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if (hit.controller.tag == "PlayerHuman")
        {
            Debug.Log("pickup");
            GetComponent<Pickup>().PickupItem();
        }
    }

my pickup objects have box colliders and rigidbodies, they are neither kinematic nor their trigger is on. They have gravity.

Nothing happens when my character walks over them

I don’t believe OnControllerColliderHit() will be called if it’s not on the same GameObject as a CharacterController. In other words, it won’t be called on the Pickup, only on the CharacterController object. You should, however, be able to use OnCollisionEnter (though I recommend making it a trigger and using OnTriggerEnter).

Continuing the discussion from RunOverPickup not working with character controller:

I am able to use OnTriggerEnter to pickup objects, but for some reason OnCollisionEnter is not working. I want some physics properties on spwanable items , hence I am adding rigidbody. The pickup objects have rigidbodies are a non-kinematic

private void OnCollisionEnter(Collision other)
{
    var player = GameObject.FindGameObjectWithTag("PlayerHuman");
    if (other.gameObject == player)
    {
        Debug.Log("pickup");
        GetComponent<Pickup>().PickupItem();
    }
}

CharacterControllers don’t play well with reporting, it would seem. Try putting a second collider on the object, one collider as non-trigger for the physics to drop on the ground proper, and the other a bit larger (so it triggers before the charactercollider quietly moves the pickup) as a trigger. That should let you use OnTriggerEnter.

Privacy & Terms