Make player get damaged when looking at an object

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)

Fully client side :smiley:
Who doesnā€™t love math right

1 Like

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.

1 Like

Doesnā€™t work.

It doesnā€™t give off an error either.

Try a ray that is given off from the front of a player, if this hits slender man then that user takes damage

How would I do that :joy:

I really donā€™t know how to do it.

Also, I edited to script to this:

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)

HE DOES NOT HAVE A HUMANOID ROOT PART BY THE WAY!

I could insert slenderina right?

The one I inserted has a HRT

Nope, the script still doesnā€™t work. Thatā€™s a big disapointment.

Is this is a localscript or a serverscript?
Also make sure the torso of the slender model is facing forward

A LocalScript

(30303030303030)

Here is the image of it in process:

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.

  1. Fire a ray infront of the player. (Preferably length of your longest paths in a building or something)
  2. If thereā€™s a part or anything it hits, get its parent
  3. If the partā€™s parent is slender, hurt yourself.
2 Likes

Search how to do raycasting, try youtube thedevking, he explains it, and you would edit this and make it so as stated

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)

(Edit)

Take a look at these, these helped me and I am pretty good at RayCasting now

Ray casting is just firing an invisible (sort of) ray.

Raycasting: how do i do it - #3 by RedDuck765 :slight_smile:

4 Likes

Player is now getting damaged if they look north, west, east or south.

I donā€™t understand :sob:

I quit roblox scripting now ok. :sob:

From now on, I will never come back on the devForums.

Goodbye.

2 Likes

Donā€™t give up! Keep trying, no game is made in a day, have patience and try different techniques

1 Like

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

1 Like

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.

6 Likes