Attracting/Pulling Object?

Hey everyone,

I'm trying to write up a script so that when a player is within a certain range of any item it slides towards the player and destroys on collision

The thing is I cant even get the OntriggerEnter or OnCollisionEnter to work and not sure why

void OnTriggerEnter(Collider other) {

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

            Debug.Log("You've Collected an item!");
            Destroy(other.gameObject);

        }
    }

Would anyone be able to give me a heads up? I'm coding in C# not JS

1 Answer

1

Is the "IsTrigger" property on the collider you added enabled?

Edit:

You have to add a new capsule as a child of your controller and resize it. Then disable the mesh renderer and set the "Is Trigger" property on the capsule collider to enable. Then add the script to the capsule.