How to make an Imperfect Blocking System

Allow me to elaborate.

The system I want to make only allows a player to block an attack that comes from the direction they are facing. in other words, the block will not work if the attack comes from behind the player. how would something like this be achieved?

Please give the most optimal and preformant way to make this, to your knowledge. if there is another thread that sufficiently answers this, please link it below.

Thank you all for your time.

1 Like

What I found: Parry/Blocking system for combat

Figured that it would require raycast.

there is a thing called “Vector3:Fuzzyeq
that i use for a blocking system of my own in a unpublished and discontinued battlegrounds game i have.

i forgot how it works exactly but i think it returns a boolean if the vector inputted is atleast a certain ( accuracy* ) range of the inputted number next to it…

i dont know, but it works.

I have a simple function check just for this that I’ve used in systems before. But let me warn you that player latency will make this really annoying for users because they’ll be getting hit when they feel like they shouldn’t due to not seeing the enemy where the enemy sees themselves. There is not a real solution to that problem I think full-body block systems perform best for Roblox because ping in Roblox really sucks.

function CheckFrontHit(One,Two)
	local Magnitude = ((One.CFrame.lookVector*Vector3.new(1,0,1)) - (Two.CFrame.lookVector*Vector3.new(1,0,1))).magnitude
	-- Use this print to calibrate how you want it
	--print(Magnitude)  
	return Magnitude
end

if CheckFrontHit(Tool.Parent.HumanoidRootPart,Hit.Parent.HumanoidRootPart) > 1.4 then
	print("Block")
else
	print("Hit")
end

This is basically using math to see if enemy HumanoidRootPart front side is facing the back side of their target’s HumanoidRootPart.

The main type of block system I would endorse using this for is shield versus ranged projectile. When you get into melee combat the latency becomes too obvious. I’ve ran a competitive fighting community for around 4 years now that uses a block system like this and the skilled players have mastered fighting around latency to point that anyone new just thinks it’s broken.

what do you mean by the latency becomes too obvious? what about this wouldn’t be good for melee combat?

You should use The Vector3:DotProduct for this. There are great videos online explaining it i recommend just searching it up on youtube. But essentially its a method built into all vector objects that compares two vectors. it returns a value of -1 to 1. -1 means they face opposite of each other, 0 means they face perpendicular and 1 means they face the same direction.

theres never a way to make latency not appear very obvious. the two ways you can handle this is via CFrame:ToObjectSpace() comparing both the attacker and defenders RootPart CFrames, or use DotProduct like @rnoou said and compare the angles between the two attackers.

Latency means there’s a delay in what you see versus what your enemy sees. If you hit them from behind they’ll still see you in front of them. For melee combat this is very obvious. For ranged combat it is far less obvious. I seriously do not recommend you do this type of blocking for a melee system, but if you do, the function I provided works perfectly. Just adjust the math to suit your expectations. Only number you should touch is the >1.4

you’re right, this works fine. but, i dont quite understand how it works. would you mind giving an explanation for all of the numbers?

1 Like

actually, no. i figured it out on my own. thank you so much for all of the help!

1 Like

Use the print i included (uncomment it) to see each number printed based on where you hit to get good calibration for your system and how you want it.

i already did that. thank you though!

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