Thursday, February 12, 2015

Unreal Engine Dev Update #10: Meet my new Player Character - The Camera

As usual, it's been a while since I put up a development update. In my previous update, I had mentioned that I made some major changes to my project. Oh and btw, since this is basically a learning project for stretching my understanding of game design, I'm just calling it Project Horizon. Current plans are that I'll be releasing it for free. This is kind of an experimental game project for me. So I'm just gonna through around some stuff at it and see if they work. Alright let's get back to the changes. First of all, I'll just note down the two major changes here:
  1. I've set the RTS Camera in my game as the default player character. 
    2.  A new AI Controller to control the player units.
So I'll get to the first one in detail now. For starters, I've been using my player units as the default characters in the game. And that would seem like the sensible thing to do. Accessing the active player units are also a lot easier that way. And as mentioned in my previous posts, I've been using a custom RTS Camera (not the one that comes with the default character in Top Down Template) to move around the map. I noticed that when I'm playing the game, I'm just moving around the camera most of the time, while issuing commands based on a UI. It's almost as if the camera is the unit that the player is controlling. It's the only thing in the game over which I have almost constant control. The units that I command, move on their own and fire on their own, once I issue commands to them. And that kind of leads to the thought behind the reasoning for the second change. But getting back to the camera implementation, I'm still using a character blueprint for the camera. As a result, I can easily access the camera from any place. And I'm doing that a lot since I need it to automatically follow the units when they are executing their commands. But apart from this change, the core functionality of the camera remains the same as before. I had written a brief account of it's implementation in one of my earlier posts. Feel free to check it out here:

Unreal Engine 4 Dev Update #7: RTS Camera System for Top Down Turn-Based Games

Now let's get down to the second major change. As mentioned above, I'm currently using AI Controllers to control all the units in the map. One version for the AI  and another for the player units. And why would I do that? Two reasons: Utility and Efficiency. The Utility comes in the form of Behavior Trees. The AI Controller puts the power of Behavior Trees at my disposal. I did not have this luxury when I was using a player controller. The Behavior Tree enables me as a developer to not spend unnecessary resources on checking player state, since it can take care of it much more efficiently. The code that I had implemented prior to Behavior Trees for handling player state involved checking lots of conditions at every tick. Basically, the logic was not simple. It was not elegant. It was the type of code, that you want to change right from the moment you implement it. I was happy to push all of it into the Behavior Trees. So in hindsight, it is the transference of the player unit control to the AI Controllers that propelled me to use the camera as the default player character. It took some time and confusion to get through these changes. But things look a lot cleaner now. Plus the game is working fine. And I'm actually happy that I got rid of that code. Before I end this post, I hope this will do justice to the title:
With that I'm rounding up this update. I don't have any videos directly related to this as both these changes were mainly under the hood. The gameplay basically remains the same as before. There have been a lot more changes since, but I think I'll have them in another post. Meanwhile feel free to browse through my Youtube channel (link below) as I've already uploaded some of the new gameplay videos following this update. 

Alright that's it for now. I'll hopefully have another update before the end of this week. See you soon.