So doors, They swing open and closed. Unfortunately they don't that easily when creating an interactive system within Unreal Engine 5, I decided to create a door system that locks to keep virtual thieves away! This was quite difficult to do and took some time. Firstly I had to created the key, a golden orb, I started by creating an actor blueprint and adding a static mesh to it. I then had to add an event for the release through the motion controller and add a detach from actor which would keep the rotation, location and scale of when it is let go while simulating physics. The other side is the grab function which is similar except instead of a detach it is an attach to actor that has the rule of snapping to the actor (the hand) and will rotate with the hand but it will keep the scale as the world setting, this side also doesn't need to simulate physics.
For the key i kept the mesh as a simple sphere and added a gold mesh to the key to allow for the user to easily see that what the key is without having to try and figure it out. I chose a sphere as it added some visual interest as everything else was a cube or some form of rectangle which also allowed for the user to easily know what the key is.
The next part was creating the lock itself, it was a pretty similar start to the key by making an actor blueprint but this time adding a plane, The event graph for the keyhole was a little complicated compared to the key. Firstly i had to create the piece that would detect the key by using a line and making a start and end point and using this as the detector and the key to follow until it hits the unlock mechanism.
I then created the sliding mechanism to make the key slide along the path, this was done by finding the closest point on the path (either the end or start) This would then allow the key to move the location up or down this set path (dependant on where its located and if the location of the key was equal to the end of the path the key would attach to the line segment and slide up the segment and allow the key free movement again which would trigger a boolean to set the value to locked as the key had been removed.
On the other hand if the key is begun at the start of the path it would attach and slide down until it hits the end of the segment through the same type of code as the lock feature, this would also stop physics from playing effect unless the line is not fully followed. Once the segment is fully followed by the key mesh a boolean (the same one but activated this time) of unlocked would be triggered and allow for movement within the door.
The only other part of this event graph i had to create was to get the location of the start and end point of my spline, which needed to be connected to the event begin play node and output where the XYZ of the spline was located for each part I needed to measure (aka my start and end point).
This is my entire event graph and how i laid it out.
This is the mesh for my keyhole, The spline shows the line follow path for the the key. The keyhole is also lowered enough within the scene so when the key is inserted it disappears to allow the user to know when the key has been inserted properly.
After this I created the door and the door mechanisms, I did this with an actor mesh and then adding a static mesh for both the door and door frame. After doing this I could move onto the nodes, The first one i created was to set up the functions for the door knob to be able to be grabbed and released. This was pretty simple the main thing i had to add was to get the location of the hand compared to the handles and if it was equal, it would allow the door to move.
The next part of the event graph i created would be the part that would detect if the door was locked or unlocked, this would just run it through a few question nodes of "has this node been triggered?" and then into a branch which would take all this information as a condition and then set the door to locked or unlocked, this part would also allow the door to move until its back in the closed position with or without the key and only allow the door to open when the key was inserted.
I also needed to add the nodes to allow the door to rotate, This was set up so the door could only rotate, This was done by running it through conditions to decide if it was unlocked, if it was the door would be able to change the world rotation. This part would also help add to the door key being removed and still being re-locked.
I kept the door mesh simple and used the door and door frame from unreal that are pre-built in. This saved me alot of time instead of spending ages modelling the door and frame i was able to simply get on with the nodes.
Below is the entire event graph and how it is all laid out.
My first outcome I had accidentally replaced a change rotation node to location so my door was sliding up and down, This was quite a simple fix and one of the only main problems I encountered during the process of creating the door, While it was complex to create it wasn't to difficult to create the basic side of the door such as the beginnings of the nodes. After it was complete I was quite happy with the outcome as the door locks and unlocks with the key, but also has a auto re-lock when the key is removed and the door is closed so that it can still be closed without the key inserted and doesn't freeze in place wherever it was left when the key was removed, The door also has a auto click that will click it into place when the door is mostly closed, This was just to keep the door looking and feeling quite clean when it closes. Overall i'm really happy with the outcome of this task.
https://drive.google.com/file/d/1tnCemhbY0P8t5ZWxa38mNsBNNCi6GsPD/view?usp=drive...
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.