How to find if player is behind other player

Hello.

I am making a knife backstab system like Arsenal, and I have a question: how do I do this?
Using Magnitude doesn’t work because it always returns a positive number.
What could I do to make this work?

Thanks

Try to determine the side of the knife strike

What is your current way to detect knife hits?

you can get the look vector and position of plr1 (getting stabbed) and position of plr2 (stabbing) then you can do some vector calculations to get the location of plr2 with respect to plr1

My current way to detect a hit is by firing a ray from P1 to mouse.p and checking if there was a valid hit with a character.

How would I do this? ? ? ? ? ? ?

that would be pritty complex, you can instead create a surface GUI on back face of the player torso with a transparent button that is scaled to the entire face and if the button gets pressed, you can check the distance between players and decide weather it is a backstab or not

Whenever you ray hits the character, compare hit CFrame to torso/humanoidrootpart CFrame. whenever hit position was behind the player, backstab.

Which math would I use to do this?

-- player1 is the player with the knife, and player2 is the target player
local forwardVector = player1.Character.HumanoidRootPart.CFrame.lookVector
local directionVector = (player2.Character.HumanoidRootPart.Position - player1.Character.HumanoidRootPart.Position).Unit
local dotProduct = forwardVector:Dot(directionVector)

if dotProduct < 0 then
    -- Player1 with the knife is not facing the targeted player2
    -- Perform backstab logic here
else
    -- Player1 with the knife is facing the targeted player2
end

use this logic

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