- Home /
Making locked gates/doors (C#)
Hey, I'm in need of a quick solution for making a locked gate or a door. I have a Hinge Joint attached to the gate, but what I'd like to know is how could I make the door unable to be opened before an event has ran, and able to be opened after the event? Is there a way to sort of lock the rotation of the door until it doesn't have to be locked anymore?
Many thanks, TAP.
I do it this way: I attach a collider to the door and when the door is activated I mark the collider as isTrigger so the function OnTriggerEnter is called when the player approaches and there I play the animation and open the door
Answer by robertbu · Jul 10, 2014 at 02:41 PM
A couple of things to try:
Set the isKinematic flag to true on the Rigidbody until the door can open.
Set rotation constraints on the door until the door can open.
http://docs.unity3d.com/ScriptReference/Rigidbody-constraints.html
Just make sure you don't inadvertantly set some isOpen flag. The door could very well start getting its state wrong.
Your answer
![](https://koobas.hobune.stream/wayback/20220613153720im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Pick up key and unlock a locked door 1 Answer
Wait for user input in modal menu? 0 Answers
Detecting moment when GameObiect is created in hierarchy. 1 Answer