Enemy: Flying Drone

I still need to implement couple of enemies before starting to create gameplay demo. This time I will focus on flying drone which will:

  • Avoid other enemies or obstacles,
  • Make his way to player,
  • Use Flying character movement,
  • Explode on colliding with player,

In my earlier blog I have implemented drone which will attack player from distance. You can read the tutorial here.

I will use the same asset from Popup Asylum. It’s free and it’s really great!

IMPORTING DRONE

Import PA_Drone.fbx as Static Mesh. Scale should be set to 100 and remember to deselect combine meshes.

importdrone

You should get couple of meshes.


ADDING SOME FUNCTIONS TO BASE ENEMY

Open BP_BaseEnemy and add one function:

GetDistanceToPlayer – pure function, one float output.

getdistancetoplayer

We will be using this function a lot in the future so it’s good to have it in BaseEnemy.

Add one variable: DeltaTime and assign it to Tick:

tick


CREATING DRONE BLUEPRINT

Create new ENUM named MovementDirection. Open it and add those:

enum

This will be used for deciding where Drone should go.

Now create new blueprint based on BP_BaseEnemy named BP_Enemy_FlyingDrone and open it.


Components

I want to have rotating engines and wings, so there is couple of things need to be done in components.

I will go step by step here.

CapsuleComponent:

  • Capsule Half Height: 30,
  • Capsule Radius: 30,

Mesh should be none.

UI_Health:

  • HiddenInGame: True,

Add new scene component named ForwardTrace:

  • Location: (X=75.896011,Y=0.000000,Z=0.000000)

Add new scene component named UpTrace:

  • Location: (X=0.000000,Y=0.000000,Z=61.875702)

Add new scene component named DownTrace:

  • Location: (X=0.000000,Y=0.000000,Z=-59.432049)

Add new scene component named BackTrace:

  • Location: (X=-77.302223,Y=0.000000,Z=0.000000)

Add newBox Collision component named Box:

  • BoxExtend: (X=15.064343,Y=24.425884,Z=14.042534)
  • Location: (Pitch=0.000000,Yaw=0.000000,Roll=0.000000)
  • Add OnComponentBeginOverlap event, leave it blank,

CharacterMovement:

  • DefaultLandMovement: Flying,
  • DefaultWaterMovement: Flying,
  • AirControl: 1
  • MaxFlySpeed: 400,

Now add new scene component named RootMesh:

  • Rotation: (Pitch=0.000000,Yaw=-90.000000,Roll=-0.000000)

Now add new Static Mesh Component from PA_Drone_PA_Drone and attach it to RootMesh:

  • Collision Presets: should ignore Pawn.

padrone

Add new scene component named EngineRotation and attach it to RootMesh scene component:

  • Rotation: (Pitch=29.999979,Yaw=89.999878,Roll=0.000315)

enginerotation

Add new scene component named RightEngine and attach it to EngineRotation scene component:

  • Location: (X=1.776338,Y=-22.932190,Z=0.000008)
  • Rotation: (Pitch=-0.153412,Yaw=-91.727509,Roll=49.851082)

Add new Static Mesh component from PA_Drone_PA_DroneBladeRight and attach it to RightEngine scene component:

  • Location: (X=-22.932198,Y=-1.776337,Z=0.000008)
  • Collision Presets: should ignore Pawn,

bladeright

Add new Scene Component named LeftEngine and attach it to EngineRotation scene component:

  • Location: (X=1.776335,Y=22.932194,Z=0.000008)
  • Rotation: (Pitch=-0.148865,Yaw=-91.727875,Roll=50.153404)

leftengine

Add new Static Mesh Component from PA_Drone_PA_DroneBladeLeft and attach it to LeftEngine scene component:

  • Location: (X=22.932198,Y=-1.776337,Z=0.000008)
  • Collision Presets: should ignore Pawn,

leftblade

Add new Static Mesh Component from PA_Drone_PA_DroneWingLeft and attach it to EngineRotation scene component:

  • Rotation: (Pitch=0.153399,Yaw=-91.727539,Roll=50.148811)
  • Collision Presets should ignore Pawn,

Add new Static Mesh Component from PA_Drone_PA_DroneWingRight and attach it to EngineRotation scene component:

  • Rotation: (Pitch=0.148850,Yaw=-91.727905,Roll=49.846519)
  • Collision Preset should ignore Pawn,

Here you can see all components.

components


Event Graph

Add new variables:

  • DroneMovementDirection (ENUM MovementDirection – Default: Forward),
  • isNearPlayer (bool),
  • HowNearFlyToPlayer (float),
  • EngineRotationFlyingUp (Rotator: (Pitch=39.999977,Yaw=89.999969,Roll=0.000319)
  • EngineRotationFlyingForward (Rotator: (Pitch=-30.000000,Yaw=89.999763,Roll=0.000248)
  • CurrentHealth should be set to 10,
  • MaxHealth should be set to 10,

Add new custom event named Explode.

explode

RadialForce properties:

radialforce_details

This will enable physics on Drone static meshes and do small explosion effect.

Add new custom event named OnNearPlayer

onnearplayer

Add event Die:

die

Before moving forward create new User Widget named DroneAttack.

droneattack

It should have one Image filling whole screen. And animation with changing the Alpha from 1 to 0 during one second.

On Construct play this animation.

playanim

This will be used as “flash” the player when drone hit him.

Go back to Drone Blueprint and add new custom event ExplodeOnPlayer.

explodeonplayer

This will create the widget and add damage to itself so Drone will die as well.

Create new custom event named CustomTick – this will be our movement functionality for the Drone. This is big event so here’s the parts:

customtick_false

This is functionality when Drone is far away from player. He is performing checks if something is blocking his movement. Changing DroneMovementDirection. For now nothing will happen because we aren’t driving movement from DroneMovementDirection.

Here’s the rest part.

customtick_true

Drone is near player and he will check if something is behind him. This won’t happen but maybe you would like to stop the Drone and attack from distance. Thanks to this drone will move up to avoid bumping with other enemies.

Add BeginPlay event:

beginplaydrone

Now create Event Tick and here will be our movement implementation depending on DroneMovementDirection.

Tick is big as well so here’s the first part responsible for rotating the engines and look at player.

dronetick_part_1

Then 0 is responsible for movement.

dronetick_part_2

Direction is used to drive MovementInput. There is one issue here – forward for drone is hardcoded as -Y. My levels will be created this way but your’s could have forward vector as X. If your drone is not moving forward – for example is moving right – this is the place to fix this out.

The last empty event is OnComponentBeginOverlap (Box) this is the place when drone hits player.

overlap

That’s all. Here you can see how it works:

Creating ShooterTutorial takes a lot of my free time.
Buy Now Button
If you want you can help me out! I will use your donation to buy better assets packs and you will be added to Credits /Backers page as well.

Implementing game is taking time but writing about it is taking much more effort!

3 thoughts on “Enemy: Flying Drone

  1. Pingback: Creating Gameplay Balance System – Part 2 – Patterns and Manager | Shooter Tutorial

  2. Another note if you’re using your own models and scene files – after correctly setting all your axes for the components, don’t forget to add collision to each of your drone meshes. Otherwise when you blow up the drone it’ll stay in what looks like one piece and fall through the floor.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.