How to hit a wall with a weapon?

I’m trying to get a wall hitting animation to work for a while now. I want a clash animation to occur right on the spot of the wall the weapon had collided. This is a 2D action platformer.
I am trying to get something like what we see in Hollow Knight, where the clash animation occurs right at the tip of the wall instead of the inside.

I feel like I am missing something here…

I’ve tried the following:

//1
Instantiate(effect, GetComponent<CapsuleCollider2D>().bounds.ClosestPoint(other.GetComponent<TilemapCollider2D>().transform.position), Quaternion.Euler(0, 0, Random.Range(0, 90)));

//2
Instantiate(effect, other.GetComponent<TilemapCollider2D>().ClosestPoint(new Vector2(GetComponent<CapsuleCollider2D>().bounds.center.x + (0.8f * transform.parent.localScale.x),GetComponent<CapsuleCollider2D>().bounds.center.y)), Quaternion.Euler(0, 0, Random.Range(0, 360)));

So far 2 gives better results than 1. But with 2, the clash animation goes inside the wall instead of just outside at the edge of the wall.

I am not sure if I get you right, hopefully this will help.

Imagine a capsule collider around a melee weapon and you hit a wall. I want sparks to show up at the point the weapon hit the wall. Right at the edge.

Hi Grazing, I believe you can try using the Physics2D.Raycast it will return raycastHit2D to get the hit point location where you can use it for the spawning position. Make sure to use the layer mask for any unwanted layer.

When your weapon hit the wall and the collision happen at that instance you can call Physics2D.Raycast

https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html
https://docs.unity3d.com/ScriptReference/RaycastHit2D.html
8256831--1080777--upload_2022-7-6_11-34-1.png

Hmm interesting. I will look into this approach. Never thought about using raycast for this. Thanks