So I made this function that loops with dot checking if the player is facing the other player before damaging for my breath particle script. I also used magnitude to check the range between the two. My problem is that the breath particle is quite slim, and the magnitude is too big of range.
If the players facing the other player that’s good, but if theyre not inside of the particle but more of next to it they still get damaged. Matter of fact they can be pretty far away from next to it and as long as i’m facing their direction it just damages.
How can I make this work so that it perfectly checks distance for z and x?
Here’s the function I created:
function icebreath()
breath1.Enabled = true
breath2.Enabled = true
breath3.Enabled = true
while iceybreath do
wait(.25)
local playersInHitbox = {};
for i,oPlr in pairs(game.Players:GetPlayers()) do -- oPlr = 'other player'
if oPlr ~= plr and oPlr.Character and oPlr.Character:FindFirstChild("HumanoidRootPart") and root then
local oRoot = oPlr.Character:FindFirstChild('HumanoidRootPart');
local v = oRoot.Position - root.Position;
if v.magnitude < 15 and v:Dot(root.CFrame.lookVector) > 0 then
playersInHitbox[#playersInHitbox + 1] = oPlr;
end
end
end
for _,cPlr in pairs(playersInHitbox) do
cPlr.Character.Humanoid:TakeDamage(5)
end
end
breath1.Enabled = false
breath2.Enabled = false
breath3.Enabled = false
end