# How to make block break from behind?

hello,im making a rpg game. i want the block to break if you get attacked from behind. just like on gpo and tsbg. in my combat system when you block, a tag named “blocking” gets added to your character. and in my hitbox system, if hitbox hits an enemy that haves blocking tag, the hitbox loop breaks. can you help me?

1 Like

You can check if the person that is attacking the player is infront of the player using the CFrames of the two humanoidrootparts.

can you explain it a bit more please?

do ya know strongest battlegrounds? If you hit from behind, you won’t block it
so you get damaged, but in this case, he want to break the block instead of hit the player

Sure.
You want to check if the attacker is behind the person that is blocking.
This is the code snippet I linked:

``````local isInfront = false
local isNextTo = false
if Core then
local angle = math.acos(Core.CFrame.LookVector:Dot((Child.Position-Core.Position).Unit))
isInfront = angle < math.pi/2
isNextTo = angle < math.pi/1.65
end
``````

In this code snippet, `Core` is the main part, and `Child` is the part you’re comparing it to.
The angle variable gets the angle from the `Core` part’s orientation to the `Child` part using the Dot product of the look vector of the `Core` part (so its orientation) and the relative position of the `Child` part to the `Core` part.
By calculating that Dot product, we get the cosine of the angle. To get the actual angle, you need to use the inverse cosine function on it (`math.acos()`).
Now, you have the angle between the two parts and can determine whether or not the `Child` part is behind the `Core` part by comparing the angle to an already specified threshold.

``````local isInfront = false
local isNextTo = false
if Core then
local angle = math.acos(Core.CFrame.LookVector:Dot((Child.Position-Core.Position).Unit))
isInfront = angle < math.pi/2
isNextTo = angle < math.pi/1.65
end

if not isInfront and not isNextTo then -- equivalent to isBehind
break
end
``````

edit: Actually, I think this would only work for one side, so you’d have to use the absolute value of the angle.

``````    isInfront = math.abs(angle) < math.pi/2
isNextTo = math.abs(angle) < math.pi/1.65
``````

no no i want it to hit the player too. if i can achieve how to detect if someone is hitting behind, i can just stop block animation and remove the blocking tag.

ok now i understand, thank you for letting me know

the punch
[“R”] = function(plr)
local chr = plr.Character

``````	if chr:HasTag("Stun") or chr:HasTag("Using") or chr:HasTag("HeavyCD") then
return
end
local st = os.time()
local hitplrs = {}
playRandomHitSound(game.ReplicatedStorage.Movesets.BoogieWoogie.Sounds.Swings,chr)
while os.time() - st < .05 do
local hitcast = hb.CreateBB(chr, Vector3.new(5, 5, 7), chr.HumanoidRootPart.CFrame * CFrame.new(0, 0, -4))
for i, v in pairs(hitcast) do
if not table.find(hitplrs, v.Name) then
table.insert(hitplrs, v.Name)
v.Humanoid:TakeDamage(15)
stunplr(v,1.2)
playRandomHitSound(game.ReplicatedStorage.Movesets.BoogieWoogie.Sounds.HeavyHits,v)
knockback(chr, v, .2, 60)
knockback(chr, chr, .1, 20)
playRandomHitAnimation(v.Humanoid)
end
end
end
end)
chr:RemoveTag("Using")
end)
chr:RemoveTag("HeavyCD")
end)
end,
``````

the hitbox module:
function module.Create(Attacker, Size, cFrame)
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {Attacker}

``````--HitboxIndicator(Size, cFrame)
local Parts = workspace:GetPartBoundsInBox(cFrame, Size, Params)
local Victims = {}

for _, Parts in pairs(Parts) do
local Victim = Parts.Parent
if Victim:FindFirstChildWhichIsA("Humanoid") and Victim:FindFirstChild("HumanoidRootPart") then
if not Victims[Victim.Name] then
if Victim:HasTag("Dodge") then
--				movesets[Victim.AbilityValue.Value](Victim,Attacker)
break
elseif Victim:HasTag("IF") then
break
elseif Victim:HasTag("Blocking") then
break
else
Victims[Victim.Name] = Victim
print(Victim.Name.." damaged")
end
end
end
end
return Victims
``````

end

where should i add that? sorry im a bit new to combat scripting.

I believe it would be:

``````			elseif Victim:HasTag("Blocking") then
local HRP_V = Victim:FindFirstChild("HumanoidRootPart")
local HRP_A = Attacker:FindFirstChild("HumanoidRootPart") -- assuming Attacker is the character

local isInfront = false
local isNextTo = false
if HRP_V then
local angle = math.acos(HRP_V.CFrame.LookVector:Dot((HRP_A.Position-HRP_V.Position).Unit))
isInfront = angle < math.pi/2
isNextTo = angle < math.pi/1.65
end

if isInfront or isNextTo then
break
else -- is behind
-- break blocking loop, maybe just by removing blocking tag, idrk how it works in your system
end
else
``````
3 Likes

thank you so much!! it workedd

1 Like

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