When the player will look at one place and then turn his head to another place, the jumpscare will come, how can I do something like that?
Easiest way to do this is probably to lock all players to first person camera. Then with your script keep track of the direction their camera is facing. There’s many ways to do this.
Hello, first of all, thank you for your reply. I’m making a horror game so the player camera is already set to first person camera. So how can I do it? can you write a sample script? Thanks.
theres multiple ways to do this depending on what you’re after. do you want it to occur when a player looks in a specific direction? at a specific object? whats the trigger for the jump scare?
This will get you started but you will need to add more to it:
Like @hotpocket285 said you need to define how your trigger works after you get their camera.
Hello, first of all thank you for your reply. I want jumpscare to come when the player enters a dead end in a maze and turns his back on the wall.
Why don’t you send a raycast from the camara position?
You can make that if it’s instance is a detector part, then it calls the function
alr sick, theres two ways i would attempt to do this. both ways require knowing the direction facing outwards of the wall, put a decal and get the face of the wall that the player would be looking at. next you’d want to do one of two methods, you can do object space to figure out how the player’s rootpart is oriented compared to the wall. this can be done via this function of CFrame
With ObjectSpace you supply 2 CFrames, say you want to figure out if the wall is in front or behind the player, you can do:
plrRootPart = plr.Character.HumanoidRootPart -- both arbitrary directories, you can put your own location for both wall = workspace.Wall -- both arbitrary directories, you can put your own location for both -- check if the player is facing the wall or not local objSpace = wall.CFrame:ToObjectSpace(plrRootPart.CfFrame) -- this value is the local space of both CFrames, you can check the Z value to figure out what is in front or behind.
second way is using dot product. dot product returns a radian value which is the angle between two vectors.
plrRootPart = plr.Character.HumanoidRootPart -- both arbitrary directories, you can put your own location for both wall = workspace.Wall -- both arbitrary directories, you can put your own location for both plrRootDirection = plrRootPart.CFrame.lookVector -- player look direction wallDirection = wall.CFrame.lookVector -- change this to right vector or up vector depending on the wall face local playerLookDirection = math.deg(math.acos(plrRootDirection:Dot(wallDirection))) -- returns a direction 0-180 of where the player is looking
if you’ve any more questions i can elaborate further on the functions and what they do more precisely.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.