Collision detection with child object, versus parent

Hello everyone.

I am trying to stop my player upon collision with a ‘wall’ object, but not when it is actually nose-to-nose touching the wall itself, but just a little before. With a ‘buffer’ kind of.

To do this, I tried to put a child object along with the player object, but the child object does not seem to be triggering the collision. It is still being only done on the character itself.

Here, showing the feet touching the wall, versus being ‘back’ a little bit.
8244609--1078464--upload_2022-6-30_13-29-48.png

Here, with the ‘buffer object’ visible, around the character, showing that the ‘wall’ and the ‘buffer’ are overlapping.

The code, within the player object currently.
void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.tag == “Wall”)
{
Debug.Log(“Wall Hit”);
movingToTarget = false;
}
}

I also had this in its own script, attached to the buffer object, referencing the player object, but there was no change.

Does anyone have any suggestions on how I can improve/fix this?

Thanks all.

Does the new object have a Collider to trigger collisions?

Thanks RadRed,

Yes, the ‘buffer’ object itself, and the testing ‘wall’ object both have this.

This is on the buffer. I’ve played with either, one-or-the-other, etc, I just currently have it on both for testing/troubleshooting.
8244930--1078551--upload_2022-6-30_15-38-47.png

Does it print out anything if you take the Debug.Log outside of the if statement? It also might be better to just print out collision.gameObject.name to see what it’s actually hitting.

On a side note, it’s possible your collision matrix has it so they cannot collide, although you would have had to manually set it to do that in Project Settings > Physics.

In all the successful debug logs, it reported out ‘wall hit’. Adding the collision.go.name, resulted in ‘wall’ too (the actual name of the object itself) as well.

When the IsTrigger checkbox is set to false on the player object, and true on the buffer object… no detection/collision happens.

When I disable the collision code within the player script, and add a new script just to this buffer prefab object with that same code, it does not recognize the wall, it just moves past it completely (or even trigger debug on a collision).
8246529--1078947--upload_2022-7-1_8-33-28.png

Currently, the main player object has a player script attached to it, with a “public GameObject bufferObj;”, and that buffer cube in question is a prefab attached within it. So i don’t understand why having code on the buffer cube, wouldn’t then fire properly/at all.

I’ve never really played with the collision matrix before, but this is its current state:
8246529--1078944--upload_2022-7-1_8-31-50.png

8246529--1078947--upload_2022-7-1_8-33-28.png