Iām not sure if anyone proposed this, but, you can find the dot product of the two LookVectors: Camera LookVector and the Slenderās LookVector (preferably of the root part) and verify if itās 1 (which means theyāre facing each other). Hereās some sample code of what I mean.
local SlenderModel = SlenderModel:WaitForChild("HumanoidRootPart")
local HRT = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local function isFacingSlender()
return SlenderModel.CFrame.LookVector:Dot(HRT.CFrame.LookVector) == 1
end
RunService.RenderStepped:Connect(function()
if isFacingSlender() then
game.Players.LocalPlayer.Character.Humanoid:TakeDamage(.1) --arbitrary
end
end)
What if you back it up with some math like dot products on the server to combat the WorldToScreenPoint being unreplicated? Though itās probably just as safe as using math on the server anyways.
local SlenderModel = workspace.Slenderman.Torso
local HRT = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local function isFacingSlender()
return SlenderModel.CFrame.LookVector:Dot(HRT.CFrame.LookVector) == 1
end
RunService.RenderStepped:Connect(function()
if isFacingSlender() then
game.Players.LocalPlayer.Character.Humanoid:TakeDamage(.1)
end
end)
Tbh, in this situation I would go for the ray firing technique.
I realised there might be a problem since if you use the dot product method, the player loses health even if youāre facing slender through walls. Iām not writing another whole script since I donāt have time for that, however, Iām just mentioning the method.
Fire a ray infront of the player. (Preferably length of your longest paths in a building or something)
If thereās a part or anything it hits, get its parent
However, to add on this, hereās the script that works not considering any obstractions between you and slender.
local Slender = workspace.Slenderman.Torso
local HRT = game.Players.LocalPlayer.Character:WaitForChild("Head")
local RunService = game:GetService("RunService")
local function isFacingSlender()
return math.ceil(Slender.CFrame.LookVector:Dot(HRT.CFrame.LookVector)) == -1 --Edited
end
RunService.Stepped:Connect(function()
if isFacingSlender() then
game.Players.LocalPlayer.Character.Humanoid:TakeDamage(.1)
end
end)
What? no I didnt mean to do that, I know the concepts are hard and they take time because thats the main point of it. If you give up that easily all you have learned until now will be a waste.
āThe roots of education are bitter, but the fruits are sweetā - Aristotle
I might sound rude but thereās no point on running away from your problems, if you want something to work you need to work through it, itās unrealistic if you just expect the solution to be easy or come right at you when what you are trying to do is more complex than it seems. You canāt just say āI want to add this mechanic to my game, can someone help?ā and expect a kindhearted person to give you the code, you canāt become a programmer if you do it that way, you need to go through the school of hard knocks just like everyone. Donāt see this as an insult to you, but rather as a motivation.