Parry/Blocking system for combat

I have a question about parry/blocking system for my combat game
I am currently trying to make a blocking/parry system and i want the players who is blocking can be attacked from the back, do i have to use raycast or anything?
Are there any examples that i could learn from?

1 Like

There’s a lot of complex methods like dot product, or magnitude checks. But using raycasting works too, you can shoot the ray from the players back to see if it hits the attacking player.

1 Like

wait so i could detect if a player is facing another players back using raycast?

It’s like this. You use raycasting and shoot a line in the direction from the players back.

e.g

local Torso = ??? assign the victims torso
local Attacker = ??? -- assign the attackers character model
local cast = workspace:Raycast(Torso.Position, -Torso.CFrame.LookVector * 5)
if (cast and cast.Instance and cast.Instance.Parent == Attacker) then
-- hit from behind
end
1 Like

Add a bool value into StarterPlayer → StarterCharacterScripts

name it ‘Parrying__’

now update your scripts to detect BEFORE damage is recieved if parrying is set to false.

You could use a .Touched event to detect if the sword has hit the player or the shield, though this can be unreliable at times. Another method you could use that would be more reliable would likely be using raycasts to shoot a line from the player or sword onto the enemy player before damage is taken to check if the the sword had hit the enemy’s shield or body.

Player swings > Sword hits > Server checks validity of the swing & sends a ray to check if the player hit the enemy shield or body > Send damage through the server and finalize

thank u so much bro it works perfectly

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.