How to detect when a player turns around in first person?

Im developing a new horror game and i need to create a system that detects when a player turns around, once the player turns around they get a jumpscare.

There isnt a physical enemy behind you, it just detects when you turn your camera around.

For more info, the “Enemy” will be behind you, if you turn around and look at him you get a jumpscare. You can move forward, backward, left and right, you just cannot turn your camera around.

An example is demonstrated in this video:

Any responses appreciated!

In the demonstrated video, it doesn’t seem like they are detecting the player turning around, I’d say rather there is an invisible part following the player, and if they turn around and look at the part it detects a turn around.

basically, the way to achieve this is to have a invisible part follow the player from behind and then detect if they are looking at the part. To detect that you can use

if Part.CFrame:toObjectSpace(Character.PrimaryPart.CFrame).Z <  0 then

end

To have the part follow you just have the part looktowards you and move forward via. Cframe. Put it in a while loop and if pause if it gets into a radius of the player

if (Character.HumanoidRootPart.Position - Part.Position).Magnitude > 5 then
    local lookTo = Vector3.new(Character.HumanoidRootPart.Position)
	Part.CFrame = CFrame.new(Part.Position, Character.HumanoidRootPart.Position)
	Part.Position = Part.Position + Part.CFrame.LookVector * 0.2
elseif (Character.HumanoidRootPart.Position - Part.Position).Magnitude < 5 then
    local lookTo = Vector3.new(Character.HumanoidRootPart.Position)
	Part.CFrame = CFrame.new(Part.Position, Character.HumanoidRootPart.Position)
	Part.Position = Part.Position + Part.CFrame.LookVector * -0.2
end
	

Or instead of a part following the player, you can just have the invisible part periodically go behind the character, and when they turn around it happens, but I’m assuming you want it to happen any time. Though in a horror game setting, if there was a dead-end you could just have the part spawn behind them because they’ll have to turn around.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.