CapsuleCollider : How to get the info which part is hit?

I have build a leaning function for my FPS character.
to prevent him to look through walls I added 2 CapsuleCollider with rigidbodys around the camera.
the outer Capsule stops the leaning so the camera cannot go farther on. the inner Capsule should move the camera a bit back to the center if I walk into a wall.

so now my problem is if I push the “lean right” button and it detects a wall it will stop move. thats good. but when I let the button go and push at the same time the “lean left” button it will still stop moving the camera because I only have this one Collider…
same for the inner collider. I cannot determine if I hit a wall on the right side or on the left side…

as I wrote these lines I found a solution that could work but I still want to know if there is a simple line of code that I could add to my Colliders to determine which hemisphere is hit.

You may want to look at:

If you look at the collision class, you should be able to get the contact points. I am assuming that if you compare the contact point to the center point of the object, you will be able to determine which direction it is in.

If you are new to scripting and new to the Unity engine, you may wish to look at Raycasting.

And instead of using colliders, simply check with a ray (2, if you want to check left and right) for objects to each side.

With the information from the Raycast Hit:

… you will be able to find more details about what and where you’ve hit an object.

You can then apply your logic based on knowing where that object is.