Friday, 27 June 2014

Prototype - Flying, Exploding Drone

Enemy spec's:
  • He flying to player,
  • When he collide with player he will explode,
  • He will have different SpawnPoints, (above the ground),
  • He will be quick, 
  • He will have really low health,
  • After dead he will explode and make radius damage that can hurt other enemies as well,
It sounds it will be hard but it's super easy. I will be using MainAI_Pawn as a base for this enemy, so keep that in mind and read earlier posts.
Asset
Again will use PA SciFi Enemies and Vehicles and use Drone. I've combined all of the meshes and added two bones to the engine. You can download FBX here.
After import create PhysicalAsset for the mesh. Delete all of the bodies and create own by yourself. I've used Single Convex collisions and enabled bone break. If you don't know how to do that please read earlier post.
Animation BP
Right click on your Mesh and create Animation Blueprint. Name it Drone_AnimBP. Add new float variable: Current Rotation, and in Event Graph add some value to it.
This value will be used for gear rotation. Move into Anim Graph and add couple of Modify Bones blocks. You should know how to do that if you read earlier posts ;) 
That's all here. 

Drone Pawn
Now create new Blueprint extending from MainAI_Pawn and name it Drone_Pawn. Assing mesh to it and set animation blueprint. 

Let's do the same as earlier with Speed and Scale, you should be able to do it by yourself now. Just try it! The goal here is to have random scale and random speed. Before you start you can change Walking to Flying mode. To do that just add Begin Play event and set movement mode like here:
Thanks to this your Drone will fly now. If you want to test it out just change spawning actor in Spawn Manager to Drone_Pawn. That's all. Last thing is health this actor should have low health something like 10. 

Adding Radial Damage
Go to MainAI_Pawn and create RadialDamage event. I'm copying almost everything from PointDamage.
Now in Drone_Pawn add AnyDamage event and manage health.
Now when you kill Drone it will create radial damage and make damage to all other's enemies in radius. Unreal is making the magic where if enemy is near the explosion it will get more damage.

Flying Movement.
Well I've see that MoveTo isn't working correctly with Flying Characters yet so everything connected to Flying can be thrown to trash :) We will do our own movement then. 

This one is easy but blueprint is some kind of complex. I will use MoveComponentTo which needs Time to move from point X to point Y. First I need to process my Speed to move over time from point X to Y. 
So every time MoveComponentTo will fire - it will move the same speed even when route length will be different. That was the hardest part, let's move.

Create new blueprint "DroneController" extending from AIController. Open your Drone_Pawn and change AIcontroller (in Defaults) from AIController to DroneController. Thanks to that our Behavior Tree won't fire on this Pawn. So it won't pick location and move to target. 

Go back to content browser and create new Enum - DroneState which should have: MoveToPlayer, MovingUp and Dead.

Open drone Mesh and add two Sockets from RootBone: EndTraceSocket, TraceSocket. Don't change rotation! 
We will use them for tracing.

Open Drone_Pawn add some variables:
  • DroneState - which should be DroneState enum,  (set it to MoveToPlayer in BeginPlay,
  • Speed - float,
  • OverTime - float,
You need to set Speed and Over time in Begin Play event. Just copy above's blueprint. (two images up :) ) 

We will create CustomTick that will fire every 0.1 seconds. In UE3 there was timers I wasn't able to find them in UE4 but we can do something like that using blueprints. 

I tried to comment everything, here is the blueprint. Basically we are moving Drone to TargetPoint. If Drone is near someone he will move up and try to avoid it. If avoided - move again to TargetPoint. It's simple. The best way to learn is to try to create it by yourself - don't copy my blueprints! And - I'm not a programmer so don't trust me! :)
How it will avoid:
It's far from perfect but it's doing his job. I will polish it later: movement speed, re-tick delays, rotating mesh and engines.


Different Spawn Points
Just place couple of spawn points where you want to spawn Drones. I've created bunch of them, one higher one lower. I've renamed them so I know which one is for Drones. You need to have couple of Target Points near player as well. They should be near player so Drones will collide with him.

Now in your SpawnManager create another array for SpawnPoints and name it DroneSpawnPoints and add your spawn points to it. If you don't know how just read earlier posts. 

In SpawnManager Graph just change foreach from SpawnPoints to DroneSpawnPoints. Remember to assign CurrentSpawnPoint when spawning Drone_Pawn. Here's BP for everyone that haven't read earlier posts.

Adding Explosion Effect

I will use P_Explosion_Bomb as a template I'm not sure where I found it - you will need to download some Marketplace content and search for it.

Create an copy and name it Drone_Explosion. Disable Fire and Smoke emitters. I've deleted GPU Sprites as well because they won't work on Mobile. I've changed emitters scale to be smaller.

Create another Socket base on RootBone - name it ExplodeSocket. It will be used as impulse location for small explosion. 

Now go to Drone_Pawn and where are you enabling simulation add Radial Impulse. 
And spawn your particles when exploding. After explosion change DroneState and before it check if it isn't Dead because you will spawn a lot of particles there!
Adding Sounds
Explosion: I've found a lot of good sounds:
http://www.freesound.org/people/Nbs%20Dark/sounds/94187/
http://www.freesound.org/people/funhouse/sounds/2514/
http://www.freesound.org/people/tcpp/sounds/132098/
http://www.freesound.org/people/animationIsaac/sounds/207322/
http://www.freesound.org/people/funhouse/sounds/2513/
http://www.freesound.org/people/lorenzosu/sounds/72069/
http://www.freesound.org/people/Sancho82/sounds/78457/
http://www.freesound.org/people/Andromadax24/sounds/169775/

Import them into UE4 and create new Sound Cue. Iv'e created something like this:

Parts on hit: I will use some of those: http://www.freesound.org/browse/tags/MetalHit/
Create another sound cue and try to experiment to get the best results.

Open your drone Physical Asset and select all bones and enable Simulation Generate Hit Events thanks to that our mesh will fire Hit event on RigidBody collision.

Now go to Drone_Pawn right click on Mesh and create Hit Event.
I'm using vector length to fire up the sound because this event will popup almost like a tick. 

Engine sound: http://freesound.org/people/zippi1/sounds/17951/
Create new sound cue using this sound:
Now in your Dron_Pawn create Audio Component with this sound. It should have Auto Activate turned on. Before killing Drone you should deactivate this sound.

Attack Player
Open Drone_Pawn and create new variable which will be HitResult type. In your custom tick lets check where the player is. It would be better to use some collision events for this but this will work as well.
What you can do by yourself is to implement Drone state: AttackPlayer - when Drone is near (something around 250) he can start moving faster and rotate to player as well. 

Final Effect
In next post I will add another character - this time something more humanoid;)

No comments:

Post a Comment