I am currently working on a map generator project.
The generator can generate different setting of maps each time when play is clicked. The setting of the map , eg, width, height, size of the walk-able space can be adjust in the public parameter.
It uses random function to generate a matrix of on and off nodes,
smooth the value of the nodes according to its surround nodes, and finally use Unity mesh generator to create floor and walls.
It is still in a WIP stage.
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Thursday, 6 April 2017
Friday, 24 March 2017
Let's steal chickens! - chapter one -chicken chain
Do you remember the old Mario game on GBA that the little green Yoshi taking a long queue of egges and throwing them at the enemies?
I was having a lot of fun of collecting different colours and types of eggs.
I am making same feature in my game in an evil version (evilly smile)
So what's this feature about?
Instead of collecting egges, you collect little birds. You will be able to steal eggs from their mother bird. When your hp is low, you eat them to gain hp (poor chickens!).
Let's take a loot at our chicken in close!
The mother bird is able to generate chickens who follow their mom. When the player attack the chicken, the chicken will be stunned. Then the player can steal the chicken. The chicken starts follow the player.
To achieve the effect of chicken chain, the chicken need to follow her [target] either the previous chicken in the chain or, if there's no previous chicken, the player or mother bird.
This means, in the chicken class. There will be a Gameobject_target and a function setTarget(). The target need to be set when the chicken is created. setTarget() function can also be useful when the player is trying to steal her from the mother bird.
With the target set, the chicken chain movement will be easy, the chicken class constantly test the distance between it's target and itself. If the distance is larger than a threshold, +the chicken walk towards it's target.
Here's the effect of chicken chain!
Fun to look at , lol!
Here is the movement class of the chicken.
The following step will be create a simple movement for the mother bird , allow the mother bird to spawns chickens over time.
I was having a lot of fun of collecting different colours and types of eggs.
So what's this feature about?
Instead of collecting egges, you collect little birds. You will be able to steal eggs from their mother bird. When your hp is low, you eat them to gain hp (poor chickens!).
Let's take a loot at our chicken in close!
The mother bird is able to generate chickens who follow their mom. When the player attack the chicken, the chicken will be stunned. Then the player can steal the chicken. The chicken starts follow the player.
To achieve the effect of chicken chain, the chicken need to follow her [target] either the previous chicken in the chain or, if there's no previous chicken, the player or mother bird.
This means, in the chicken class. There will be a Gameobject_target and a function setTarget(). The target need to be set when the chicken is created. setTarget() function can also be useful when the player is trying to steal her from the mother bird.
With the target set, the chicken chain movement will be easy, the chicken class constantly test the distance between it's target and itself. If the distance is larger than a threshold, +the chicken walk towards it's target.
Here's the effect of chicken chain!
Fun to look at , lol!
Here is the movement class of the chicken.
The following step will be create a simple movement for the mother bird , allow the mother bird to spawns chickens over time.
Tuesday, 31 January 2017
Simple solution for instantiate/ recycling Game object in Unity
I have been
looking for an efficient way of generating bullets and recycling them in Unity
environment for a while. And finally, here's a very good and easy solution for
that.
Target:
Different mobs shoot different types of bullets
towards player. A reusable solution is needed for managing the bullets
instantiation and destroying.
Solution:
Instead of adding a script for the mob to generate
and destroy bullets, use a bullet pool to manage the generating and destroying
of bullets. Every time a mob shoots, the mob class asks the pool for a new
bullet. Pool checks itself for available bullets. If there is a bullet, it is passed
to the mob, otherwise a bullet need to be instantiated before it is passed to the
mob. When the bullet's life cycle is complete (either time out or hit objects)
it returns itself to the pool.
Implementation
1.The Pool
:
The Pool is
an empty Gameobject on the stage. The Pool class has a stack and two public
functions: getObject() and returnObject().
stack:
keeps
the instances of bullets.
getObject():
check
available bullets, instantiate bullets, pop the required bullet out of stack,
and return it to Mob as an Gameobject.
returnObject():
to push the
object back to stack.
2.The Mob class:
The Mob class
holds an instance of the pool on the stage. At the Moment of attacking, it calls
the getObject() function to acquire a bullet and set the transform of the
bullet.
3.The Bullet
class:
The Bullet class
holds an instance of the pool on the stage. It starts to move forward as soon
as it is acquired by the Mob. When it hits something, it hides itself and calls
the returnObject () function.
the result:
the source code for the pool:
Subscribe to:
Posts (Atom)







