Sunday 29 June 2014

10 000 views, thanks!

I just wanted to thank you all for reading the blog! It's motivating me to to post more often. Blog has been online for couple of weeks now and Today you have break 10 000 views. I'm happy to help you guys! Don't forget liking my Facebook Page;)

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;)

Sunday 22 June 2014

Prototype - Spider Polishing

Remember: 20% of your work is creating something and 80% is polishing it. This is something that lot of developers don't remember and when answering question "how much time you need?" the answer is 20%, not 100%.

So let's move into first polishing iteration of a spider. What I would like to fix:
  • Spider should rotate to player when shooting (the place where it's shooting),
  • Various spider speed,
  • Better impact effects,
  • Better dying effect,
  • Spider lasers are really annoying I can't see anything when they are shooting,
  • Bug: spider is above the ground,
  • Bug: they are still shooting at me when health < 0
And I have one thing in backlog: spider should move on walls/envrio but this is something for different post ;)

Rotate when shooting
Go to SpiderCharacter. Find MyAttack function and interpolate actor rotation like here:
Various speeds
In SpiderCharacter create new float variables:
  • MaxWalkSpeed: 160,
  • MinWalkSpeed: 80,
  • WalkAnimRate,
And add this into end of your Begin Play event.
Go to Animation Blueprint and create float variable: WalkSpeed. Open Anim Graph and find SpiderWarior_MoveForward sequence. When you click on it properties will popup. Pin Rate and assing WalkSpeed.
It's all. Try to change MaxWalkSpeed to get the best results.

Impact effect
We will use particle from Shooter Example: P_Body_Bullet_Impact.

Go to MainAI_Pawn and create new Particle System variable, default should be set to P_Body_Bullet_Impact. 

Now in Event Point Damage spawn emitter at location like here:
Dying effect
I will create ragdoll effect with bone break as well. First of all you need to have Physical Asset prepared. There is great tutorial about them here. You need to watch it all. 

Prepare your physical asset and in SpiderCharacter blueprint go to Take Any Damage event. You should have if health<0 then. Pin your ragdoll when you know that health < 0. I've pinned it with random bool as well so it won't be ragdolling all the time. 
If you want to break bones. There is an option for that in PHAT.
You should experiment with PHAT/ragdolls/breaking bones to get better results that I've.

Lasers
Just change your start color because it's to big and bloom is enabling. You can work with noise and size as well. Just experiment to have "Spider lasers are really annoying I can't see anything when they are shooting" resolved ;)

What you could do is set Target of Beam more randomly and higher. Just go to SpiderAttackNotify and to Notify Begin and add this as Target.
Sounds
There is a great site here with lot's of SFXes to use. I will put names of sounds that I will use from this site.

Before Attack Sound: "Science fiction steampunk robot spider scuttle"
Now go to your Attack Animation and create new Sound Nofity with this sound. 

Attack Sound: "Electricity High Voltage Spark Continuous Arcing" I've used Audacity to make the sound smaller.
Go to your SpiderCharacter and create new Audio Component with this sound, name it AttackSound. Auto Activate should be disabled. Now go to custom SpiderAttackNotify and in Begin Event get AttackSound and activate it. In End Event just deactivate it. That's all.

Steps sounds: "Person walking along metal bleacher isle." I've used Audacity to make each step different file. 
Pluging them into your project is really simple. Create Sound Cue - we have created couple of them earlier.
And now in Walking animation just create Sound Notify with this sound and enable bFollow.
 

Dying Sound: It's really hard to find anything good so won't be doing that now.

Spider is above the ground
This is really simple. Just go to SpiderCharacter and move Mesh down. You can use "ghost" or "toggledebugcamera" console command in-game to check if it's on the ground.

Spider is still shooting when health < 0
In SpiderCharacter find MyAttack function and before you change SpiderState check if State is < 2. 
It will prevent from shooting if Spider is Dead. As you probably remember SpiderState is 2 when we kill him. 

Still in SpiderCharacter find Damage Event and check if Health < 0. After that you should deactivate Beam.
Now go to your custom Notify: SpiderAttackNotify and check if SpiderState < 2.
You need to be sure that your Beam particle have Kill On Deactivate enabled. (in Required)

Scale
In SpiderCharacter create two float variables: ScaleMin(0.6) and ScaleMax (1.2) and in begin play event set the scale.
Final Result:
Spider isn't finished yet but it's lots of better now. Remember - there is always room for polishing and it's our first polish iteration so we will get back to this topic.

In next post I will add new flying and exploding enemy.

Friday 20 June 2014

Prototype - Enemies Health

First of all current Unreal Engine 4 HUD implementation is really pain in the ass. It's just Canvas from Unreal Engine 3. As far I know Epic is working on UI system, but we will need to wait 3-4 months to use it. That's why I will stick with Canvas for this project, but if you have a game with lot's of UI you should think about your solution or other frameworks. (scaleform for example)

This one is hard and I needed a help of a Programmer to get this done. Will try to describe it as much as I can but this functionality won't fit to other games because I've used Shooter Game example HUD.
Getting the HUD
Open Shooter Game example and find HUDAssets2 and HUDMain. Reimport them to your project. When you play shooter example you can see ammo count in bottom right corner of the screen. We will try to reimplement it to be enemies health bars.

MainAIPawn
Create couple of variables:

  • nStripes - int, default: 10  (it will be our health bars count)
  • HealthBar - float, array,
  • MaxAlpha - float, default: 1,
  • MinAlpha - float, default: 0.2,
  • dAlpha - float,
  • MaxHealth - float, default: 100,
  • fullBars - int,
And one Scene Component - HPBarLocation. 

Now create Begin Play event and fill the HearthBar array like this:
MyGame
Go to MyGame blueprint and add variable: MainAI_Pawn and name it CurrentEnemies. It should be array again. We will store all enemies in this array to be able to get it from other classes.

Spawn Manager
There is an bug on Mobile where you are casting to your classes from Level Blueprint - HUD disappear. (btw this is the first non-fixed bug that I found in UE4) That's why we will move our spawning to new class. This class will be base for spawn manager later on.

Create new Actor Blueprint and name it SpawnManager. Place it somewhere in the level. Add new variable: SpawnPoints (array from EnemyText), should be editable so you will be able to assing SpawnPoints to it from Level. So assing your spawn points to the array. 

Now let's spawn something. 
It's really placeholder spawn mechanism, simple and bugged but should be enough to test HUD.

Back to MainAI_Pawn
Create function UpdateHPBar and try to copy everything from this:
This basically updates the Alpha on the 10 bars in Health Bar.

While still being in MainAI_Pawn go to Damage Event and after setting the Health check if health is < 1 if yes then set ShouldDrawHPBar to false and CurrentSpawnPoint's IsBusy should be false as well. 

MyHud
Now move to MyHUD and create variables:
  • U - float, default: 146,
  • V - float, default: 149,
  • EnemyHPOffset - float, default: 7,
In DrawHud function:
What this basically do is going through all enemies and all HealthBars elements and draw them with offset. Scale is used to draw everything smaller when enemy is far away. At this point you should analyze how Draw Texture works hope this image will help:
That's all now just run the game and here's the result. 
Basically there is lot of better ways to draw enemies HUD but I'm far away from graphics artist. What you should try to create is fill bar and border and just scale down the fill bar it would be much more simpler than this.

In next post I will work on Spiders - first polishing iteration, there is couple of things that can be done to improve their prototype quality.

Thursday 19 June 2014

Prototype - Laser Scope

In this post I will create and add laser scope into the weapons so it will be easier to shoot. Another thing will be recoil when our arm is "steady" (when we aren't shooting) 

Laser Particle
I will use this tutorial which is really great! I've created package with everything (material, particle, textures) ready to use here, but you should try to create it by yourself.

Attaching Laser
Go to MyCharacter and create Particle System component with LaserScope FX. It should have disabled AutoActivate.

Add new bool variable into Graph and name it: bLaserScopeEnabled it should be true by default for now.

Now move into ChangeWeapon function. Create Sequence and attach LaserScope Component to MuzzleFlash socket.
Recoil when "steady"
Basically what I want to do is to have zero recoil when I'm aiming. This is really simple as well. I will check if player weren't shooting for X time and then next shoot will have zero recoil. 

Go to MyCharacter and create new floats variables: LastShootTime and ZeroRecoilTime (set to 0.5)

Now in EventGraph go to place where you have your pistol shooting. Before delays set LastShootTime.
Now go to PistolProjectile. And check LastShootTime like here. If it's < then 0.5 we won't be doing any recoil. 
You may be confused why I haven't show anything after Single Trace - it's just a copy of everything below which should be implement by you in earlier posts.

Final result
I won't be showing any video this time because it's hard to see what's happening - you need to play by yourself. Basically when you wait 0.5 seconds before your next shoot you will shoot exactly where the laser is pointing so it's much more easier to aim and create critical strikes now. +1 to gameplay.

In next post I will be adding health bars into enemies.

Tuesday 17 June 2014

Prototype - Critical Damage System

What I really like in games is critical strikes. I'm always playing rogue or some character with big crit chance and attack speed. I won't do the same here but there are couple of things that can be done:
  • If you hit enemy really near weak point there will be chance for critical damage,
  • If you get critical damage game should be able to show you this,
  • You should know how much damage are you dealing, 
Thanks to that more advanced players will be able to kill an enemy with one shoot. 

Change AnyDamge to PointDamage.
In your MainAI_Pawn replace AnyDamage to Point Damage. Do the same in SpiderPawn.

Go to Pistol_Projectile and change AnyDamage to PointDamage. Direction can be set like here:
Heart
Open MainAI_Pawn and create new Scene component - name it "Heart". There is one thing weir with components you aren't able to change them in classes that extend this actor. So open SpiderPawn and create Scene component, name it HeartSpider

Still in SpiderPawn go to Begin Play event and set Heart to HeartSpider
Go to MainAI_Pawn and to PointDamage Event. We will need to check how far from Heart we shoot. 
You can make variables to be able to quickly balance critital damage multiply and distance from heart.

Now create new blueprint, extend from Actor and name it EnemyText. Add couple of variables:
  • Text - float, (editable and expose on spawn)
  • Alpha - float, 
  • WasCrit - bool, (editable and expose on spawn)
  • GoingBack - bool,
  • Lifetime - float - default: 3
For now we will leave this blueprint because we need to add something into MyHud. So open MyHud blueprint and add two variables: TextColor(LinearColor) and EnemyTexts - this should be EnemText type and should be array. That's all for hud now.

Go back to EnemyText and create Tick Event. We will animate this actor - it will move up.
That's all here. Now move into MainAI_Pawn and PointDamage event. We would need to spawn this actor when we shoot to the enemy. 
And after spawning we need to manage EnemTexts array in HUD. So here's the rest part of Spawning Enemy Text:
Everything is ready to draw it on Hud.


HUD
Open MyHud and go to Draw Function. Create Sequence and add this to your blueprint. It will draw damage from enemies:
That's all! Now when you shoot your enemy you will see floating damage text there.

Critical Damage Projectile and Camera
Create a copy of MyProjectile name it "CriticalProjectile" and change couple of things:
  • Add spring arm as we did in Steer Gun,
  • Add camera and assign it to spring arm,
  • Change projectile speed - from 2000 to 3000,
  • Remove the mesh,
  • Add audio component with sound above,
Go to Graph and remove everything. Leave EventHit only and:

Now go to MainAI_Pawn and add sequence when we know that there will be critical strike. (before spawning EnemyText)
It's enough for prototype but it will need to be polished a lot later.

Final Result
In next post I will add laser scope to the weapons so it will be easier to aim.