官术网_书友最值得收藏!

Changing direction

If you were to compile the Blueprint, save, and play the game now, what would you expect to see? The target cylinder would move according to our speed and direction as soon as the game began. However, since we don't have any instructions that cause the target to stop moving, it would proceed in the same direction for as long as the game runs, even moving through objects and out of the level we created! To address this, we need logic that will change the target's direction periodically. This will result in a target that moves back and forth between two points regularly, much like a shooting gallery target.

To do this, we have to set up two nodes that will set the direction variable we created to two different values. Drag the direction variable into empty grid space and choose the Set option. This will result in a node with X, Y, and Z axis fields. We can use them to change the value of the direction variable to be different from the initial default value that we gave it. We want two of these nodes, so drag the direction variable again into empty space, and then change the Y axis values of the two nodes to 10.0 and -10.0 respectively.

Now we need a way to switch between these two nodes so that the direction repeatedly shifts. The FlipFlop node was created for scenarios where we know we want to alternate between two sets of actions that execute exactly once before switching each time. This fits our use case here, so right-click on empty grid space and search for FlipFlop. Select and place the node. Then connect the A execution pin to one of the direction set node input pins, and the B execution pin to the other.

Finally, we need to ensure that there is some kind of delay between executing the direction shifts. Otherwise, the direction will change for every frame and the object will go nowhere. To do so, drag the input execution pin of the FlipFlop node into empty space and search for the Delay node. This node allows us to set a delay duration, in seconds, that will postpone the following execution commands by that length of time. Place this node before the FlipFlop node and give it a duration of 6 seconds. Placing this Delay node between our Set Actor Transform node and our FlipFlop node will ensure that the direction switch enabled by FlipFlop will occur only every 6 seconds. The final product should look like what is shown in the following screenshot. Once you are done, remember to compile and save the Blueprint.

Testing moving targets

Now that we have our Blueprint updated, we can test to ensure that the CylinderTarget object moves as expected. First, we will have to place the CylinderTarget object in a position that will allow it to move along the Y axis without bumping into other objects. The coordinates I used were 410 on the X axis, 680 on the Y axis, and 180 on the Z axis.

Note that these values will only work relative to the default layout of the First Person template map. If you have made adjustments to your own level, then you can adjust either the speed or the placement of the target in your level, and test until you find a good patrol spot. Click on Play. If the Blueprint is functioning correctly, you will see the cylinder move back and forth between two points at a steady rate.

One of the advantages of using Blueprints is that they create a template of functionality that can be used across multiple objects in a scene. Find CylinderTarget_Blueprint in the Blueprints folder and drag it directly onto 3D Viewport. You will see another cylinder created, which inherits all of the functionality of our original cylinder target. In this way, we can rapidly set up multiple moving targets using the single set of Blueprint logic we created.

主站蜘蛛池模板: 蛟河市| 屏东县| 铁岭县| 江西省| 仙游县| 鄂尔多斯市| 丹凤县| 色达县| 缙云县| 孝昌县| 舟曲县| 平舆县| 赤水市| 文登市| 永春县| 田东县| 平泉县| 伊川县| 江城| 舞阳县| 双流县| 道真| 图们市| 呼玛县| 东海县| 甘孜| 九江县| 新营市| 昌乐县| 陆川县| 浦城县| 定襄县| 中超| 安新县| 鹤庆县| 瓮安县| 资兴市| 黔江区| 乐清市| 松桃| 南部县|