Thursday, 28 August 2014

The End? (week #12)

This week I finished my turn based strategy game by adding movement, the ability to attack and enemy AI. unfortunately the game did not turn out to be grid based like I hoped as I lack the programming skills in order to make that possible at the moment. The game acts like a turn based strategy game but the grid based movement and attacks are not precise.
the gameplay works by the player selecting a unit by using the left mousebutton which instantiates a green selection ring around the selected unit. the player then mouses over a series of cubes with the mesh renderer turned off, turning them back on to signal where the selected unit will move.
 if the right mouse button is pressed the unit will move to the cube and play it's walk animation. When the unit arives at its position the attack phase begins and a series of 4 cubes is instantiated around its position, if the player right clicks one of these cubes the unit will attack and play its attack animation, this will then lead to the enemy's turn.

If there are any good tutorials  on scripting a turn-based strategy game in C# using unity3D or someone could set me in the right direction please let me know as I would like to learn how to fix some of the problems I encountered. Thank you for reading

GUI and Floating Healthbars (week #11)

during this week I mainly worked on the GUI aspect of my turn based strategy game, for example floating  Health Bars for my units, backgrounds for the health bar,  text for when an attack misses and an icon for the poison status when a unit becomes poisoned. this is all handled by setting the screen position to MainCamera.WorldToScreenPoint and the position of the transform holding the script. a new rect is created at the screen position and tweaked in order to fit the right position for example this is the rectangle for my Health Bar:
Rect rect = new Rect (ScreenPos.x - 50, ScreenPos.y - 30, 100 / (100 / PlayerHealth), 15);
therectangle is also affected by the player's Health which causes it to reduced size the lower the players health becomes. A GUI.Box is created using the information shown in the rectangle but using its own GUIStyle variable allowing textures to be easily added to the health bar script.
I discovered how to created these floating GUI textures from this answer in Unity answers which I recommend you have a look at if you want to add a floating health bar to your game:
I also recommend reading the Unity Scripting API for camera.ScreenToWorldPoint which is linked here:

If you have any feedback about this post please let me know

Unit Selection (week #10)

for the selection of characters in my turn based strategy game I have used a raycast utilizing camera.ScreenPointToRay to the mouse position when the left mouse button is pressed. this ray then accesses the gameobjects that are carrying the player script allowing the public function "Selected."
On the player script there are numerous variables which are attatched but only a few are effected by the selected function, these include the public boolean selected which will be utilized to perform actions when the object's selected status is true or false and amountSelected integer which will be used to cap the amount of selected units.
when the selected function has been activated the script will then check the status of the selected and amountSelected variables, if selected is false and the amountSelected equals 0 then the selected variable becomes true and the amountselected equals 1 to prevent any more units from being selected at that time. This also instantiates a green ring similar to some real time strategy games like Starcraft and Warcraft at the position of the selected unit to provide some visual feedback letting the player know that the object has been selected.
if you are working on a project and you need some way of interacting with the world using your mouse cursor position I recommend looking at camera.ScreenPointToRay in the Unity Scripting API linked here :

Next week I plan on adding Health bars on top of units' heads which follow their position. if you have any feedback please let me know.

Final Project (week #9)

For my next project I am creating a turn based strategy game similar to games like Advance Wars, Fire Emblem and Final Fantasy Tactics but much more simplified. I plan on creating 3 Unit types, a basic melee unit  with low attack and high accuracy, a warlock type unit which inflicts poison to enemies with low accuracy and a large enemy that deals high area of effect damage with medium accuracy.

I haven't started scripting yet but i plan on using raycasts from the mouse position to perform actions like selection, movement and attacking.  I am not experienced at all with this genre so if you have any tips on how to make a turn based strategy game in Unity3D, please let me know

Shooting and Highscore (week #8)

This week was definately the most intense week I've faced during my studies as the pressure was building to finish my first person shooter. The 2 main things I added to my game were Raycast Shooting and a High score. At first I found it extremely difficult to understand Raycast Shooting as it is very different from anything I have encountered  during my studies but now it is quite simple.
I set it up by making an if statement to say when the left mouse button is clicked create a ray from the main camera transform position in a forward direction, if the ray hits a gameobject it instantiates a debris Prefab at the hitpoint. if the ray hits an object collider carrying the enemy script it accesses the recieve damage function from the enemy script.
In order to add a high score to my game I had to use System.IO to save and read .txt files. if the scorecount from my scorecontroller file is greater than the value saved on my score.txt file it becomes the new value for the score.txt file. The high score value is always displayed in a GUI.box by writing score.txt to a string as a high score variable.

My tutor Mike assisted me with all my work this week so unfortunately I am unable to provide any links to good tutorials but it is worth checking out the physics.raycast section of the Unity Scripting Api linked here : http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

Health and Score (week #7)

Learning how to add Health and a Score was definately a new experience for me as I did not really know that scripts could access variables from other scripts which blew my mind at first. The Health Bar tutorial by BurgZerg Arcade was extremely helpful with understanding how to create a basic healthbar using GUI.Box and how to make the healthbar accessible by other scripts by using public static variables. here is the link to the tutorial series if you want to check it out.
Adding score to the game was very similar to adding health. this was done by adding a score controller into the game and using public static variables that were accessed by the enemy script when it was destroyed by my grenade prefab. The value of the score was placed in a GUI.box with the text "Score: " attatched. A tutorial which helped me with understanding the score is UnityChat's Coin Collecting tutorial which uses coins instead of score but it is basically the same premise. here is the link to the tutorial

Next week I expect to have fully completed my first person shooter game by adding Raycast Shooting and further developing the score in my game by adding a Highscore.

Animation (week #6)

This week I put a lot of work into animation and making my enemy game objects perform different actions at certain distances. The animation was fairly simple to pick up and use as I was using prebuilt prefabs I gathered from the assets store in Unity3D already built with an animation controller and animations.
The animations were performed using the Animation.Play() and Animation.Stop() functions using several if statements to determine when these functions should apply. Here is a link to the Unity Scripting API if anyone is interested
In order to determine the distance from the player to the enemy, I created a float using Vector3.Distance and using if statements which check if the value of the distance is greater than a certain number or below it. once again here is the link to the Unity Scripting API for Vector3.Distance

Next week I expect to learn more about health and scoring in my game and I will let you know my findings.