From the course: Unreal Engine Blueprint Interaction for ArchViz Projects

Determining swing direction, part 1 - Unreal Engine Tutorial

From the course: Unreal Engine Blueprint Interaction for ArchViz Projects

Start my 1-month free trial

Determining swing direction, part 1

- [Instructor] Time now to make a determination as to which way our door is going to swing, when we first interact with it. which will require a number of calculations to be put in place. Again, there are multiple ways in which we could approach this, but what we're going to do is firstly, calculate where in the level the player is currently positioned. Secondly, where the door is sitting in the world, in relation to the player, and then finally figure out which side of the door, the user is stood on. Based on positive or negative return values. Quite a lot to do. So with our door blueprint still open then, let's make sure that we are viewing it's event graph so that we can make a start creating the logic. As the first thing that we will want, is a reference to the scene route. Which we can create by dragging on its component section of the UI, and placing it into our graph. This will be the starting point for calculating which side of the door, the player is stood on. So let's drag out from here, and choose the get world location option, which can take an actors positional data in the world, and give us access to it. We will then drag out from our int underscore door custom vent, and cast to our BP underscore character blueprint. Now this will enable us to get some data from the character blueprint, such as the user's current location, as they go to interact with the door. Now doing things this way means that the script only fires as and when, it's required. Dragging from the object input of the cast node, let's type and add, a get player character node. This is our reference to the player character. So from the get player character node, we can drag from its output. And this time search for an add a get actor location node. This means that we now have the world location of the door, and the player's location, at the time of their clicking the mouse, are interacting with the door blueprint. Meaning this is the perfect time to introduce some simple maths, to help figure out if the player is in a positive, or negative location in relation to the door. Information that we can then use to tell the door, which way swing. Let's drag from the actor location node then, and add a vector minus vector node, into which we can pipe the world location node, specifically into it's second input. And this will give us the distance between the player, and the door. Which is perfect for helping figure out, if they are in the positive or negative position. Indeed to make this easier for the engines to calculate, we can round the value between one, and negative one. To do this we will drag out from the vector minus vector node, and add a normalized node. Once normalized, we can drag from this node, and create a dot product. To complete the maths here, we will need to drag out from the seen route, and create a get forward vector node. Which we can then pipe into the second input, of the dot product node. This means we will always know which direction the door is pointing. And those give us the ability to figure out whether the player again is stood, on the positive or negative side of the door. We will then create a new variable, making sure that it is set to be a float value, which will ultimately be the dots product. This being a very important piece of information, as without it, we could run into the problem of as the player clicks to interact with the door, and then walks through it. Well, the mesh could actually try to flip direction, as it gets confused as to which way the dot product is meant to be facing. So we can call this new parameter dot underscore prod. Just as a side note, we will be using this dot product node as part of the flow in the next video. And so don't worry about the fact that it has no execution input for now. So we have added a good number of nodes, and have also, hopefully given a bit of clarification as to why we are using them. The last parts of the flow, the dot product, is really the key part as regards to figuring out the doors swing direction. And so let's move on to the next video, you know, to understand and explain this a little more.

Contents