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,
1 2 |
<strong>This Tutorial has been created using Unreal Engine 4.8.2</strong>. Make sure you are working on the same version of the engine. |
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.
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.
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:
CREATING DRONE BLUEPRINT
Create new ENUM named MovementDirection. Open it and add those:
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.
Add new scene component named EngineRotation and attach it to RootMesh scene component:
- Rotation: (Pitch=29.999979,Yaw=89.999878,Roll=0.000315)
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,
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)
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,
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.
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.
RadialForce properties:
This will enable physics on Drone static meshes and do small explosion effect.
Add new custom event named OnNearPlayer
Add event Die:
Before moving forward create new User Widget named 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.
This will be used as “flash” the player when drone hit him.
Go back to Drone Blueprint and add new custom event 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:
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.
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:
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.
Then 0 is responsible for movement.
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.
That’s all. Here you can see how it works:
Creating ShooterTutorial takes a lot of my free time.
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!
Reblogged this on King Designs and commented:
Good Info for the UE4 users.
Pingback: Creating Gameplay Balance System – Part 2 – Patterns and Manager | Shooter Tutorial
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.