Translating the existing location

Now that we have a normalized vector direction and a speed value relative to time, we need to multiply these two values and then add them to the current location. First, find StaticMeshComponent from the Components panel and drag it onto Event Graph. This creates a node from which we can extract any data contained within StaticMeshComponent of the object.

Next, we want to get the Mesh Component's location. One of several ways to handle this is to look at the Transform properties of an object and extract the location from there. Click and drag the blue output pin into empty space, and then type Get World. Select the GetWorldTransform option to create the node. A Transform contains information about the rotation and scale of an object, in addition to its location. This is useful because we want to ensure that we preserve the rotation and scale of our target even as it is moving, and we need this data to create a Transform value from our new movement information.

Now, we want to break down the Transform into its Component parts so that we can use only the location in our calculations while preserving the rotation and scale. Drag the output pin from the GetWorldTransform node, and search for the Break Transform node to add to our graph. There is another way to access the Transform Components: you can right-click the output pin and select Split Struct Pin.

Now, we need to add the necessary nodes to add speed and direction to the location information we just extracted. Right-click on empty grid space, and then search for and select the Make Transform node. This marks the end of your calculations, so make sure that it is positioned to the right of all of your other nodes. The Make Transform node has three inputs: Location, Rotation, and Scale. The Rotation and Scale inputs should be connected to the Rotation and Scale output pins on the Break Transform node we created earlier.

Next, we need to multiply the Direction vector and the Speed float we calculated. Drag the output node of the Normalize node into empty space, and search using *. Select Vector * Float and connect the green input pin to the output of the float multiplication node that we used with Speed.

Our final calculation step is to add Speed and Direction to the current location we calculated. Click on the yellow vector output pin of the new multiplication node, and then drag it into empty space. Search using + and select the Vector + Vector node. Ensure that one input pin of this addition node is connected to the previously mentioned vector multiplication node, and then connect the other input pin to the Location output pin of the Break Transform node. Finally, drag the output pin of our addition node onto the Location input pin of the Make Transform node. When you are finished, the result should look like this:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset