Best way to do a frontal-only shield?

I’m trying to figure out the best way to implement a shield for a 3rd person melee combat game. Basically what I want to do is make it so that when I hold down the right mouse button, all attacks that hit my player in the front do no damage. My melee system is very simple, the characters right now are just shooting projectiles that disappear after a few feet.

I tried having a box collider parented to my player, positioned at the front, and activate/deactivating it on Fire2, but if I get too close to my enemies, their attacks actually go through the box collider because they’re clipping through it.

Is there a way I could calculate the position of the collision of the melee projectiles when they hit my character, and determine if they are on the front of him?

Have you tried any other kinds of colliders or combos of colliders?

How are you activating/deactivating the box collider?

You could take the approach of making a if condition where if the projectile hits you without the shield give damage but if it hits the shield and you give no damage. This could be done with a trigger behind the shield for those that got through. :idea:

Colliders get messy keep it simple.

                Vector3 targetdirection = transform.position - enemy;
                float direction = Vector3.Angle(transform.forward, -targetdirection);
                if (direction <= fieldOfView)
                {
                //in frount
                }
                else
                {
                //not in frount
                }

… but if you really want to work with colliders, the Character collider returns flags which tell you what side(s) collide :slight_smile: