I looked around for a few tips but I haven’t found exactly what I am looking for so I would appreciate an answer.
I have a wall, and I want that wall to know what hit it (most likely the player). So if I get close to it, I want a variable GameObject on the wall to know what Object hit the wall. Most post seem to show how you can detect what YOU hit, not the other way around.
Also, do both objects need Collision Boxes? Any of them absolutely require RigidBody?
If you want the wall to be able to detect what is hitting it you can do this via OnCollisionEnter() on the Wall’s script. Assuming the player GO has the tag - “Player”, this should output when the player collides with the wall.
void OnCollisionEnter(Collision collision) {
if(collision.gameObject.tag == "Player"){
Debug.Log("The player has collided with the wall!");
}
}
“Also, do both objects need Collision Boxes? Any of them absolutely require RigidBody?”
You should be able to use an OnCollisionEnter function that will tell you what object just ran into you. As far as I know you will need one of the objects to be have a rigidbody.
void OnCollisionEnter (Collider other)
{
// Do whatever
}
If you put this onto your wall other will be whatever just hit the wall.