Creating a wall impact effect

ok, i have worked on this one for a few days and i can not figure out a way to make this work.

I have a gun firing projectiles at a wall… i want the shots to create a small “hit” effects on impact… depending on my distance from the wall sometimes the effect is on the edge of the wall and other times it is inside the wall.

how can i make it only create the hit effect at the edge of the trigger. Here is my code to check for hits. this is attached to the projectiles.

if (other.tag == "Indestructible")
		{

			Instantiate (indHit, transform.position, transform.rotation);
			Destroy(gameObject);
			
		}

I am relatively new to programming :slight_smile:
ken

This happens because computers calculate with discrete time steps (frames).

Every frame a couple of things are done like applying physics and calling the Update method of every monobehaviour. This means that object don’t move continuously but rather small steps at a time. This is unnoticeable for us humans but we can see the effects of it in cases like yours.

Collisions basically work like this: Object gets moved by physics → check if colliders intersect. Since your projectile is fast (i assume) it might enter the wall quite a bit. If you speed up your projectile even more, you will notice that the collision will start to fail completely. I’ve been doing some test and posted the results on the forum if want some more information.

To solve your problem you should not place the hit effect at the position of the bullet but rather at the position of the collision. The collision class used in as argument in the OnCollision method contains this information.

For the correct rotation of your hit effect, you have to align it with the normal of the collision. The exact implementation depends on your setup. I’d also suggest to move the position of your hit effect a tiny bit up along this normal to avoid ugly overlaping.