- Home /
How to make door open and close both ways?
I have a basic door that opens and closes but I want it to open away from the player depending on what side of the door the player is on. Like in Half Life 2.
I figure I need to get the player transform.forward and give that info to the door script but I'm not sure the best way to do that.
Answer by Jordash · Dec 01, 2018 at 12:37 AM
Passing the player's world position into the door's InverseTransformPoint will give you the position of the player in the door's local space. From there you can check the x or z axis of that vector is negative to determine which side of the door the player is on. Whether you'll check z or x depends how you've set up the door.
Using the InverseTransformPoint worked. Had to change my targetRotation and closedRotation from vector3 to Quaternion while keeping my openRotation to vector3. After that I had to use "Quaternion opRotation = Quaternion.Euler(openRotation);" and make my targetRotation to opRotation and use "Quaternion.Euler(-opRotation.eulerAngles);" for the opposite rotation.
There's probably a neater way to do this but I got it to work. Thanks for the help.
Your answer
Follow this Question
Related Questions
How to make a sliding door and add a trigger event? 0 Answers
How can I control each door lock state individual and also to control all the doors lock states ? 0 Answers
How to make script affect only one this game object 2 Answers
Help. Newbie trying to have more than one button powered door a scene 1 Answer
How to combine animation control with custom script based control for NPCs and player to use doors. 0 Answers