• Help with getting a players direction/angles please.
    2 replies, posted
Hello Facepunch I've recently had an idea of a little script I want to work on but I have no ide on how to approach this. When you're looking at a player and hit him at the back of the head, it should make him unconscious. But what strikes across my brain is that how can I know if I'm looking at the back of his head, because of course we only want this to work when he is facing the opposite direction to us. This is what I have...It's nothing but there is something... [CODE] -- This will all execute in the player take damage hook. local victim = player:EyeTrace().Entity local victimAngles = victim:GetAngles().Yaw if victim:IsPlayer() then victimHasBeenHit = true end [/CODE]
You'll want to use victim:EyeAngles() instead of GetAngles. Convert that to a forward directional vector. Now, get the normalized directional vector between the attacker and the victim. ( (attacker - victimposition):GetNormalized() ) Compute the Dotproduct between the two and that value can be used to determine if the attacker is attacking a position that's 'behind' the player. So if that passes just make sure the player was hit in the Head Hitgroup and there you go. [code] local vec = Angle(0, victim:EyeAngles().y, 0):Forward(); local dir = (attacker:GetPos() - victim:GetPos()):GetNormalized(); local d = vec:DotProduct(dir); --tr being your EyeTrace performed earlier. Or you can use victim:LastHitGroup() I believe. if (d <= -0.5 && tr.HitGroup == HITGROUP_HEAD) then attacker:ChatPrint("You hit that guy in the back of the head!"); end [/code] The code is untested, but it should do the trick.
Thanksss
Sorry, you need to Log In to post a reply to this thread.