How to detect if a part was touched from behind/front/left/right

Hello! im making a gore shooting game and i made a headshot mechanic that works, it basically replaces the normal head with the gore version of the head, the problem is that if i shoot the head from behind, the damage is going to be in-front of the dummy, it doesn’t make sense, i know i have to make models for each side but i don’t know how to make it so the damage faces whereever the head was shot (for example: i shoot the head from behind, so it spawns the head with the damage behind the head)

Why don’t you rotate the head so it faces the player ?

that might work but i don’t know how to exactly do that

Use the handy CFrame.lookAt(currentPositionOfTheHead,thePositionOfThePlayer) the first paramater is where you want the head to be the second paramater is where you want your head to look at.

ill try that out, thank you! (20 + 20 - 10 characters)

One more thing to make sure im not stupid, by “CurrentPosition” im suppost to use the head.Position right?

Yes (filler because i can’t send a message with less than the minimum character allowed)

it works, thank you very much, but i got one more question, is there a way to easily detect if it was shot from behind? it looks kinda weird when you shoot it from behind and it has a skull in the front, its like you shot it from the front but also the back at the same time

The way to do it is using the dot product, basically what it does is that if you have two vectors and use the dot product on them it will return a number that tells you if they look in the same direction (1 if they look in the same direction 0 if they are perpendicular -1 if the their directions are opposite to each other) the dot product always returns a number between -1 and 1 given that both vectors are normalized (lenght of 1).Now in your case what you would do is get the direction that the player is facing by taking the cframe of the humanoid root part and use the LookVector propery the look vector is always normalized so we don’t have to worry about that, then take the look vector of the enemy the same way you did with the player that shot after that use the dot product of the two vectors and add check if the result of the dot product is less than some number close to -1 but not too far.

if v1:Dot(v2) < -0.5 then
      print("Shot from behind")
end

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