UDK Auto-Turret (Core Function)
UPDATE: There has been a consistent problem that the turret only causes splash damage while projectiles seemingly pass through the player. Thanks to Mr. Shamalinia this has finally been fixed! The solution is to use an unknown object (marked as “???”) for the Spawn Projectile instigator input, not the instigator output by the player spawn event. Attaching a Dynamic Volume is also no longer necessary. I will be rewriting the tutorials to include these changes soon! For now, here’s an updated image:
Through this tutorial I will explain how to create a form of projectile firing turret through kismet, and I will explain a variety of ways it may be implemented. If you wish to skip the tutorial—not the advised route—you can visit Hourences and copy my kismet snippet for “A Turret Setup” into your own editor. Also, this tutorial is intended for users moderately familiar with the Unreal Engine and Kismet.
The first step is to attach a Dynamic Trigger Volume to the player (a Dynamic Physics Volume will work as well). In the screenshot above, the Dynamic Trigger Volume is commented as Target. The Get Location and Rotation node doesn’t work on the player as a target, but it does work on Dynamic Trigger Volumes, which is why attaching a Dynamic Trigger Volume to the player is necessary for the turret to work. First, at an enabled Player Start in your level, add a small Dynamic Trigger Volume centered at the floor; a 64 x 64 x 64 volume will do. The Volume is centered at the floor so that projectiles will not pass ineffectually over the player’s head.
Now, in Kismet, create a Player Spawned event. From there create an unknown Object variable (Marked as “???”) to connect to the instigator arrow. Create an Attach To Actor action, and connect its input to the output of the Player Spawned event. Connect the instigator to the Attach To Actor target. Now, select the Dynamic Trigger Volume in viewport, and create an object for it in Kismet. Connect the Dynamic Trigger Volume object to the Attachment of the Attach to Actor node. A way to test this setup is to manually attach (as opposed to attaching through kismet) a movable point light to the Dynamic Trigger Volume; if the light doesn’t follow the player, then the Volume isn’t following either.
Although any event can be used to attach a dynamic object to the player, a spawn event is the best. This is because in other events the player’s exact location is not definite, while an action instantly following a player spawn is. In the case of multiple spawn points, comparing the Spawn Point object of a Player Spawned event to the Player Starts on the level will determine where the player is spawned and where the dynamic object should be to accurately attach to the player.
The next step in creating the turret is to create a Get Location and Rotation action, which is under New Actions > Actor. Connect its input to the output of the Attach to Actor node. Note that a secondary event can start the Get Location and Rotation action, instead of causing the turret to fire on the player immediately upon spawning. Connect the Dynamic Trigger Volume object to the target of the Get Location and Rotation node. Create a vector variable and connect it to the location arrow of the Get Location and Rotation node; a vector for rotation is not necessary.
Now, create a Spawn Projectile action, which is under New Actions. Connect its input with the output of the Get Location and Rotation node. Connect the previously created instigator object (marked as “???”) to the instigator on the Spawn Projectile node. Connect the previously created vector from the Get Location and Rotation node to target location on the Spawn Projectile node. Now, create a new vector variable to connect to spawn location on the Spawn Projectile node; this vector determines where the projectile spawns and is fired from. One easy way to determine a vector is to place an object in the editor where you want the projectile to start, and then in the object properties open the movement and location categories, and the vector will be marked. After this vector is copied into Kismet, delete the object used to find the vector location.
To complete the turret, add a Delay node, connect its input to the output of the Get Location and Rotation node, connect its output to the input of the Get Location and Rotation node, and set the delay amount in the properties or through a float value. The amount of delay will determine the rate at which the projectiles fire. All that remains is to choose the projectile type through the properties of the Spawn Projectile node, and adjust the system according to your need.
Potential modifications for this turret setup include reseting the Dynamic Trigger Volume at the active Player Start upon player spawn by using a Set Actor Location node, adding moving components to make the spawn location dynamic, randomizing the target vector through simple mathematics to make the turret less accurate, or creating a Take Damage event on an in game object to allow for destruction of the turret. The turret setup I have demonstrated is simple, but it can be modified heavily.