Hello, I was intending to make a door that can only be opened from one side, and I wanted to detect what direction the character is facing the door from to determine whether or not the door will be opened. What would be the best way to do this, and how?
I don’t really need a full script, I just need to know what the ideal method would be for this, and how to use it. I already have a working door, all I need now is just to know how to detect the direction the player is facing the door from in order to fill the condition for opening it.
Not sure if you’ve tried this yet or not, but you could try sending out a raycast from the head/humanoid root part and then using pre-calculus to get the exact angle (by making a triangle out of the vertical line through the door, your raycast , and connecting the ends together to make a triangle)
although, that depends on how realistic you want it; you can then change that (ex. if you want any angle from 45-90 degrees to work, make an if-else loop that checks the above result with the allowed parameters)
This can be dot using :Dot() on the player’s humanoidrootpart’s lookvector.
Pretty much :Dot() just sees how close two vector3s are to facing the same direction
Guide (not mine): The Ultimate Guide to Vector3:Cross() and Vector3:Dot()
This did not help because the player can then open the door by simply pointing their character towards where the door is facing, rather than having to be in front or behind the door to be able to open it. I need something relative to the position of the character, to check if the character is behind or in front of the door, not if the character is facing the same direction the door is facing.
Create one part on Each Side of the Door, make it transparent and weld it to it. And then just check which Part is the Closest to the Player, for example… if the Left side Part is Closest to the Players then it’s the Left Side that’s the Player wants to open the Door From.
Or if that’s not what you meant, and you want it so that when the player isn’t looking at the door, they can’t open it… you can use Proximity Prompt or just Raycast.
I am using a proximity prompt. The part method won’t really work, but I did find something that did work for me after implementing it to my code: How to make a one way door? - #5 by Moonvane