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.

No comments:

Post a Comment