Hey everyone! For my game’s vault system, I tried creating a condition that check if the player is in a Y axis close to the Y axis of the part hes vaulting on. I achieved that, but it only works at one face of the part, and not both of them (Example: 90 deg works, but not -90)
Here’s the code:
local function AngleCheck(part, maxDifference)
local playerOrientation = workspace.CurrentCamera.CFrame.LookVector
local playerYOrientation = math.deg(math.atan2(playerOrientation.x, playerOrientation.z))
local partOrientation = part.CFrame.LookVector
local partYOrientation = math.deg(math.atan2(partOrientation.x, partOrientation.z))
return math.abs(playerYOrientation - partYOrientation) <= maxDifference
end
-- Function:
if partInFront and userInputService:IsKeyDown(Enum.KeyCode.Space) and canVault and partInFront.Name == "Vault01" and humanoid.FloorMaterial ~= Enum.Material.Air and AngleCheck(partInFront, 25) then
--code