Opening doors both ways

I’m looking for a way to open door both ways, relative to character position. From the way the player is facing, the door should open that way. I’ve searched every tutorial and youtube video and I cannot find anything that would help me

Check if it’s facing the door or not by using the door’s and the player’s forward vector in the calculations.

Hope it helps!

Picture or video would be much appreciated !

A simple dot product should do.

This thread should help you.

Are you worried about which way the character is ‘facing’ or where the character is… ie: What if the player backs into the door… you will want it to still open the correct way no?

Get door forward vector and player forward vector. Make branch condition and thats it.
Depending on door rotation you may use forward or right vectors for door.

Yes I’d want the door open the correct way no matter the way character is facing. So far I’ve made a trigger box and it’s working only if player enters it by moving forward. if the player enters the trigger from the side, then it starts opening doors the wrong way. I kind of solved that problem by adding narrow hall and frame to the side of the doors so that the only way to trigger the door is by moving forward

You could also make a dot product with a vector coming from the position of the door and the player and the forward vector from the door.

If the dot product is > 0, open backwards the forward door’s vector, is it is <= 0, open it towards.

Something like this:

if ( dot ( door.pos - player.pos , door.forward ) > 0 )
      //open the door backwards forward vector
      //open the door towards forward vector

Couldnt you just put a trigger box on either side of the door, no matter which direction you come from, you are either entering one trigger box or the other. One trigger box animates the door (sequence) one way. The other one animates the door the other way (sequence).?

The simplest way to do this would be to have 2 triggers - 1 on each side of the door. The trigger would fire an event on overlap that could use a Timeline to SetActorRotation of the door in the correct way.

Make sure your pivot point is at the corner so the door opens correctly.

Hope this helps!

Problem with two triggers is you activate the door to close and open opposite direction upon entering other side unless you logically gate it

I would code it so you have two events in the door open forward and open backwards. I can see some bugs with people on both sides but let’s start here

now we just need to figure out which to play based on side of door

We can determine this by doors location vector - players location or doors forward vector and players location or even getting the look at rotation from door to player to yield if it’s - or positive.

Based on that play on of the events


You are right that it could create some issues - but nothing that cant be solved easily. You could just have a variable that keeps track of whether the door is open or closed so the player doesn’t open a door while its already open. In the end I think we need more information from Roginich on what exactly does he want.
@Roginich, do you want the door to open on proximity? Do you want the player to face the door and press a button? There are many different ways to get this working based on your design :slight_smile:

Here is my solution

Time line is just running an alpha of 0-1 float track over 1 second

That works great, thanks!

Fun puzzle to solve keep them coming :slight_smile: