Created
October 18, 2016 05:53
-
-
Save sigsegv-mvm/bda5c53af428878af6889635cd787332 to your computer and use it in GitHub Desktop.
Backstabs, brought to you by 2D vector dot products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reverse engineered from TF2 ServerLinux 20151007a by sigsegv | |
bool CTFKnife::IsBehindAndFacingTarget(CTFPlayer *pVictim) | |
{ | |
CTFPlayer *pSpy = ToTFPlayer(this->GetPlayerOwner()); | |
if (pSpy == nullptr) return false; | |
Vector2D wsc_spy_to_victim = (pVictim->WorldSpaceCenter() - pSpy->WorldSpaceCenter()).AsVector2D(); | |
wsc_spy_to_victim.NormalizeInPlace(); | |
Vector temp1; pSpy->EyeVectors(&temp1); | |
Vector2D eye_spy = temp1.AsVector2D(); | |
eye_spy.NormalizeInPlace(); | |
Vector temp2; pVictim->EyeVectors(&temp2); | |
Vector2D eye_victim = temp2.AsVector2D(); | |
eye_victim.NormalizeInPlace(); | |
if (DotProduct2D(wsc_spy_to_victim, eye_victim) <= 0.0f) return false; | |
if (DotProduct2D(wsc_spy_to_victim, eye_spy) <= 0.5f) return false; | |
if (DotProduct2D(eye_spy, eye_victim) <= -0.3f) return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment