Monday, November 30, 2015

Week 10 -raycasting and a health bar !

For this week we learnt about how to use ray casting which as the name indicates is simply a ray being cast against all the colliders within the scene.

Although I initially found using ray casting slightly challenging reading up on the unity documentation helped and thus I am referencing them below although I have to find a way to use it in my current project, maybe to place the torrents? (Unity, n.d.).

While working on the game itself I found it difficult to make a health bar thus I asked for help to one of my peers who recommended that I use a tutorial video on how to create a health bar in unity using the UI canvas and a few colors.

In order the make the health bar you would first need to create a canvas and change its render mode to world space in order to resize it and make it small enough to only hold the health bar after which you can add a green colored image to it looks like a health bar, in order to give mine a more realistic feel I first added a black background then resized two colored images to fit inside it.














In order to show that the health is decreasing you will need to make a script to change its scale so It would appear as the health was decreasing .The code is very simple thus I am only placing a screenshot of it .(XOctoManx/Youtube, 2015)




























References
Unity. (n.d.). Unity - Scripting API:. Retrieved from http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

XOctoManx/Youtube. (2015, May 2). Unity 5 Tutorial: Easy Health Bar C# - using localScale [Video file]. Retrieved from https://www.youtube.com/watch?v=87R0PziLDJ0&app=desktop


Week 9 - Somethings to be done .......

This week we started working on the enemy waypoints , we would push empty game objects and  place them onto the stack and pop them as the enemy reached a certain checkpoint .Though it may sound simple it is actually , i don't mean to cause any unnecessary  nervousness but it is not  as easy as it sounds . Before we start you should add the namespace " using System.Collections.Generic ;  " .
This name space gives access to interfaces and classes that define generic collections .

In order to start off doing this you need to create an stack of vector3 , this can be done by writing "wayPoints new Stack<Vector3>();" .  Next declare a public gameobject enemyPath , in enemy path assign the waypoints for the transforms .Next you need to create a foreach loop to push t the waypoint positions into the stack and later . Note this will only push everything into a stack , we will create another function to transform the enemies .

Making the other function , it will be called transforming Position .To start of make an if to check that waypoints are not equal to 0 then do something  .Within the if  get the next point to move towards  using vector3 targetPoint = wayPoints.peek , this will get the position to move towards .

We will declare a float called step in the function , which will multiply a newly declared speed float variable by time.deltatime , name this transformSpeed .Next we will make a vector3 called nextPos which will equal to vector3.movetowards () ; in the move towards specify current transform.position  ,  targetPoint . speed variable  . Now we have the code to transform the position of the enemy over time , i would recommend to make speed float public  and specify the speed of 2.0f  and increase it in small increments or decrements to get a desired speed .

Next make an if condition to check  if the transform.position == target point then you can pop from the waypoints stack . After the if , next we will need to jump into vector3 nextPos , this can be done by saying transform.position = nextPos . 

This is what your code will look like , in order to make mine slightly cleaner i have created two functions .The first function is called in start   and the second in update .



My goal for the next week is to start working on the health bar and maybe the torrent I would need to shoot the projectiles .

Bibliography 


Microsoft developer network. (n.d.). System.Collections.Generic Namespace. Retrieved November 29, 2015, from https://msdn.microsoft.com/en-us/library/system.collections.generic(v=vs.110).aspx
Dotnetperls. (n.d.). C# Stack Collection. Retrieved November 29, 2015, from http://www.dotnetperls.com/stack