Last active
April 6, 2023 16:14
-
-
Save howmanysmall/39ec29093fad83d0dd73810dd5b1f12f to your computer and use it in GitHub Desktop.
determines if you can backstab
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
-- Compiled with roblox-ts v2.1.0 | |
local NORMALIZER_VECTOR3 = Vector3.new(1, 0, 1) | |
local CanBackstab = function(attacker, victim) | |
local attackerHead = attacker:FindFirstChild("Head") | |
if attackerHead and attackerHead:IsA("BasePart") then | |
local victimHead = victim:FindFirstChild("Head") | |
if victimHead and victimHead:IsA("BasePart") then | |
local _exp = victim:GetPivot().Position * NORMALIZER_VECTOR3 | |
local _arg0 = attacker:GetPivot().Position * NORMALIZER_VECTOR3 | |
local attackerToVictim = (_exp - _arg0).Unit | |
local attackerEyeLevel = (attackerHead.Position * NORMALIZER_VECTOR3).Unit | |
local victimEyeLevel = (victimHead.Position * NORMALIZER_VECTOR3).Unit | |
return not (attackerToVictim:Dot(victimEyeLevel) <= 0 or (attackerToVictim:Dot(attackerEyeLevel) <= 0.5 or attackerEyeLevel:Dot(victimEyeLevel) <= -0.3)) | |
end | |
end | |
return false | |
end | |
local default = CanBackstab | |
return { | |
CanBackstab = CanBackstab, | |
default = default, | |
} |
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
const NORMALIZER_VECTOR3 = new Vector3(1, 0, 1); | |
export const CanBackstab = (attacker: Model, victim: Model) => { | |
const attackerHead = attacker.FindFirstChild("Head"); | |
if (attackerHead && attackerHead.IsA("BasePart")) { | |
const victimHead = victim.FindFirstChild("Head"); | |
if (victimHead && victimHead.IsA("BasePart")) { | |
const attackerToVictim = victim | |
.GetPivot() | |
.Position.mul(NORMALIZER_VECTOR3) | |
.sub(attacker.GetPivot().Position.mul(NORMALIZER_VECTOR3)).Unit; | |
const attackerEyeLevel = attackerHead.Position.mul(NORMALIZER_VECTOR3).Unit; | |
const victimEyeLevel = victimHead.Position.mul(NORMALIZER_VECTOR3).Unit; | |
return !( | |
attackerToVictim.Dot(victimEyeLevel) <= 0 || | |
attackerToVictim.Dot(attackerEyeLevel) <= 0.5 || | |
attackerEyeLevel.Dot(victimEyeLevel) <= -0.3 | |
); | |
} | |
} | |
return false; | |
}; | |
export default CanBackstab; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment