Checking radians between parts

I need to get the direction where your player is getting punched from relative to characters rotation to identify a backstabber from a real man facing face to face. Previously I’ve used two magnitude checks, one at the HumanoidRootPart and other slightly offset forward from it but today I want to find the actual angle the attack comes from in radians for more detailed use.

ultraYee

So how on earth?

I’m slightly confused with your question, but if you are trying to find whether the player was punched from behind, would not PointToObjectSpace() be helpful?

Say, you want to check if PlayerA punched PlayerB from behind. You can take torso of playerB and do PlayerB.Character.Torso.CFrame:PointToObjectSpace(PlayerA.Character.Torso.Position). If you took the Z axis of this returned Vector3 and subtracted from it half of the torso’s Z-size (which is 0.5 I’m pretty sure), if that value is positive then PlayerA is behind PlayerB.

I’ve been checking that with the magnitude check I mentioned, this time I want to get the angle where attacker is relative to lookVector.

You could use :Dot() for this, I recommend this video implementing an NPC’s FOV which should give you an understanding on how it works! https://youtu.be/BUwAcW_18Ws?si=gLQ9PHViMfLVM5Y5
You can use the same technique used in this video to check if an attacker is in a victim’s FOV.

This was useful, thanks!

local g = game.Workspace.Gybron.HumanoidRootPart
local m = game.Workspace.Marco.HumanoidRootPart

local ding = (g.Position - m.Position).Unit
local mLook = m.CFrame.LookVector
local mDot = ding:Dot(mLook)
print(mDot)

mDot now gets me the angle I can work with.

1 Like

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