How to set up half open door and full open door?

I’m considering using two Boolean variables to track the state of a door, one for ‘Half Open’ and one for ‘Full Open.’ I also plan to have two interaction keys for controlling the different door states. When ‘Half Open’ is true, pressing E would fully open the door and set ‘Full Open’ to true. If ‘Full Open’ is true, pressing F would set the door to half-open. Is there a simpler method to implement this?

Personally, I would do it like this.

Door:

Character:

Hi, thank you for the help.

However, I am just a rookie, I did not follow the character part. Is this combination the only variable that creates a state?

What is the significance of multiplying and adding in Character, in the blueprint of the door two different angles have been set. Why is there a value of 200 here?
How do I get the last part Set, I couldn’t find it. Thank you!

Line trace is a function that makes a line in world space, from [Start] to [End]. It can hit objects and return info on what it hit. I use it to get the door reference. It has nothing to do with rotation of the door. 200 is a length of the line.

When the line trace hits the door, I use provided actor reference to get access to the door using a cast.

Then, based on the state of the door I can select what state it will be in next and set it.

IMO the only thing the character class should do is a simple try and call an interface function. Everything regarding the door should be limited to the door class.

The half/full door could work with a single button by checking to see if the player is looking at an angle (more or less parallel) or if the player is close to the opening side.

1 Like

Okay I see. How about the last one “set”? I could not find it.

I don’t think I’m capable of achieving what you’re saying. Please correct me if I have misunderstood.

As you said, I need to check the angle and the position of the players. I should have two triggers on a door, right?

I can only help for single player. :eyes:


Reasons for the interface and limit door stuff to door (chatGPT):

Here’s a breakdown of why this is a good design:

  1. Separation of Concerns: Each class has a distinct responsibility. The character class is responsible for initiating interaction, while the door class encapsulates all the logic related to door behavior. This makes each class easier to understand, maintain, and test.
  2. Use of Interfaces: By using an interface, you create a contract that any interacting object can implement, allowing your character class to interact with many different types of objects (doors, switches, items, etc.) without needing to know the specifics of what each object does.
  3. Encapsulation: All the specific door logic, such as opening, closing, locking, etc., is contained within the door class. This hides the door’s internal state and functionality from other classes, which only need to know that they can attempt to interact with the door.
  4. Flexibility: The door class can decide how it reacts to an interaction attempt. For example, if the door is locked, it might play a locked sound. If it’s a double door, it could choose to open one side or both based on the angle or proximity of the player.
  5. Reusability: By standardizing interaction through an interface, you can reuse the interaction logic across different interactable objects, reducing code duplication.

Implementing the door logic based on the player’s angle and proximity can be an elegant solution to control the door’s behavior with a single interaction button.

How to setup interfaces: Blueprint Interface | Unreal Engine Documentation


Here is a project with a simple 2 way door and a light switch:

SimpleDoor_UE5_3_2.zip (108.7 KB)

Everything needed is in Content | Blueprints folder.


No. In the project I placed 2 boxes but it’s just to make it a bit more forgiving when trying to peek. Both have different collision settings, but as long as they block visibility they’ll work with the trace.


Feel free to ask anything.

Hi, finally I got it. Thank you!

Thank you very much, a function is a function in a blueprint split into parts. It’s much clearer to see what each part accomplishes, right? Without using functions, it would look complicated and messy in a blueprint.

Also, do you have any recommendations for books or videos that I can learn from?

Free: CS50x 2024