- Home /
door animation physics
I made a door with open/close animations and a box collider. Everything works fine except when you stand in front of the door in its path and click to open/close it passes right through you.
Answer by TonyLi · Jun 25, 2013 at 02:48 PM
The animation is modifying the mesh and/or one or more "bones" (child objects) in the door's "skeleton," depending on how the animation is set up. The box collider is tied to the main game object, so it doesn't follow the mesh. In the Scene View, select the door. You should see a green wireframe representing the box collider. When you open the door, you'll probably see the door mesh move but the collider stay in place.
One way to fix this is to attach a collider to one of the child objects that actually get moved in the animation, and get rid of the collider on the main game object.
Another way, depending on your needs, is to change the shape of the collider so that it represents the open door position when you open the door. (Or have two colliders and enable/disable them as you open/close the door.) This will allow the door to pass through you while it's opening -- but, once open, you can't walk through the door mesh. From a user interface standpoint, this is sometimes nicer because the door doesn't try to shove you out of the way as it's opening.
And yet another way is to use a Hinge Joint.
The door is the child of the hinge. The script for opening and closing and the animations were added to the hinge. The box collider for the hinge covers the whole door. You cant walk through the door when it is open. The problem is if you are between the closed door position and the open door position and you click to close/open it, it passes right through you.
If you put the collider on the door ins$$anonymous$$d of the hinge, does it follow the door?
To me, it's really a design decision as to whether the "problem" is really a problem. When I'm playing a game and run up against a door and press a button to open it, I don't like when I have to manually step back to allow the door collider to swing open. For smoothness of gameplay, I don't $$anonymous$$d if the door swings through my character. It does bother me, on the other hand, if I can walk through the door mesh once it's already open. At that point I think it should be solid.
For the hinge joint, you use physics ins$$anonymous$$d of animation. You can apply a force with the motor property.
so could you make it so you could drag it open but it doesn't have to be dragged to a particular position?
What would I need to do once I add a hinge joint so that I could drag it open?
Your answer
Follow this Question
Related Questions
How to stop first person player from walking through animated door 1 Answer
Rotation Y axis is bugged. 2 Answers
Begginers question, Simplifing a script, opening two doors with 2 overlapping triggers. 1 Answer
How do you make ripples for character in water? 0 Answers
Created an Open Close Animation, but script wont activate both doors? 1 Answer