#magnitude hitboxes not working

1 messages · Page 1 of 1 (latest)

young wind
#

idk what im doing wrong

char.PrimaryPart.CFrame = CFrame.lookAt(char.PrimaryPart.Position, destChar.PrimaryPart.Position)
        local lv = char.PrimaryPart.CFrame.LookVector
        local resVector = char.PrimaryPart.Position - destChar.PrimaryPart.Position
        local normRes = resVector.Unit
        task.wait(1)
        local dot = lv:Dot(normRes)
        local deg = math.deg(math.acos(dot))
        
        local hit = deg < arc
        
        print(hit, deg)
full cove
# young wind idk what im doing wrong ```lua char.PrimaryPart.CFrame = CFrame.lookAt(char.Prim...

the issue is with your vector calculation youre subtracting in the wrong direction

local resVector = char.PrimaryPart.Position - destChar.PrimaryPart.Position
char.PrimaryPart.CFrame = CFrame.lookAt(char.PrimaryPart.Position, destChar.PrimaryPart.Position)
local lv = char.PrimaryPart.CFrame.LookVector
local resVector = destChar.PrimaryPart.Position - char.PrimaryPart.Position
local normRes = resVector.Unit
task.wait(1)
local dot = lv:Dot(normRes)
local deg = math.deg(math.acos(dot))
local hit = deg < arc
print(hit, deg)
young wind
#

lemme just test it out rq

#

alr it works but now it has another bug but im pretty sure i'll be able to fix it, i'll ask again if i cant fix it tho

winter rootBOT
#

studio** You are now Level 7! **studio

young wind
#

ok nvm then dot is somehow returning a number larger than 1

#

how

full cove
#
char.PrimaryPart.CFrame = CFrame.lookAt(char.PrimaryPart.Position, destChar.PrimaryPart.Position)
local lv = char.PrimaryPart.CFrame.LookVector
local toTarget = (destChar.PrimaryPart.Position - char.PrimaryPart.Position).Unit

print("LookVector magnitude:", lv.Magnitude)
print("ToTarget magnitude:", toTarget.Magnitude)
print("LookVector:", lv)
print("ToTarget:", toTarget)

local dot = lv:Dot(toTarget)
print("Dot product:", dot)
#
local dot = math.clamp(lv:Dot(toTarget), -1, 1)
local deg = math.deg(math.acos(dot))
young wind
#

ohhhhhhhh i get what the problem was

#

i was defining the values before running the other things

#

hol up

#
hum:MoveTo(script.Parent.HumanoidRootPart.Position)
        char.PrimaryPart.CFrame = CFrame.lookAt(char.PrimaryPart.Position, destChar.PrimaryPart.Position)
        task.wait(1)
        local lv = char.PrimaryPart.CFrame.LookVector
        local resVector = destChar.PrimaryPart.Position - char.PrimaryPart.Position
        local normRes = resVector.Unit
        local magRes = resVector.Magnitude

        local dot = lv:Dot(normRes)
        local deg = math.deg(math.acos(dot))
        
        local inRange = magRes <= range
        local inArc = deg <= arc
        local hit = inRange and inArc
        print(hit, dot)

legit just had to move the task.wait thing

#

goddamn