Tanshaydar's Place
Currently nothing
Filed under: Paralycid, Programming

Amnesia-like Door & Interaction Mechanics in Unity

I see people keep asking for the same thing over and over. Amnesia: The Dark Descent was an awesome game with superb gameplay, and White Night was a success thanks to that mostly. I can see why people would like to have that mechanic in their games, but really, it has to fit in the concept.

I’ve been working on Paralycid and its gameplay for a very long time now, and this is what I have achieved with built-in Unity physics & my programming skills.

Here’s the video, sorry for the heavy breathing, I was also testing something else:

I have to say that this took a very long time and I am not willing to share the complete code, however I can guide you on the tricks.

1) Joints
If you want to simulate physics in your game, you have to have a knowledge on how real-life physic works.
Take the door for example, it has hinges and rotates around a (fixed) pivot point. Therefore, you know that you need to use hinge for your door, and in Unity this is hingejoint.
You can access properties and methods of hingejoint component while scripting, and it is up to you how to handle those options.

2) Limitations
You know that a door does not rotate around hinge 360 degrees. It’s usually between 80 – 120 degrees. So, you’ll have to fix that in hingejoint system. Here’s a screen from mine:

3) Force
Well, in order for hinges to work, you need to attach a rigidbody. If you have a rigidbody, then you need a collider. If you have a collider, you can see other physics objects interacting with door. This is force, you apply a force on the door collider, and it behaves accordingly. Therefore, in order to manipulate door behavior, you need to apply force on the door. However, there is an easier way in Unity for that. Hingejoint object comes with ‘motor‘ and ‘acceleration‘ components and you can access these via scripting. Thus, enabling you to simulate force on physics simulation.

4) Interaction
This is the trickiest part. Because you need to have a player with mouse (or more generally, axis) movements. Since Paralycid is currently a PC game, I take mouse as the first. There are two movements of the mouse, X-Axis and Y-axis. Obviously, Y-Axis part is not necessary for conventional door mechanics, unless it is an hatch or something like that.
So you need to have a script attached to either your player or door that will catch mouse movements and apply the necessary changes to hinge.

Note that physics in digital environment is often fragile and it tends to break. You’ll need to put some limitations and restrictions on either editor screen or through script. It took me a long while to make it appealing, but the base was only 3 days work. More about it can be seen here: http://teamfrombeyond.com/whats-wrong-with-the-doors/

Verba Volant, Scripta Manent

This site uses Akismet to reduce spam. Learn how your comment data is processed.