Monday, November 30, 2015

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

No comments:

Post a Comment