Friday, 28 February 2014

Day Two: The Moving Obstacles

Here are day 2's checklist:
- implement road obstacles
- implement life system
- implement frog home
- implement a simple GUI

It's been a long day for day two. Whenever I think I've done something, another problems pops up but that's part of the process. Unfortunately, everything on the list wasn't checked and the things I've done today are:

- Camera movement from lower half to upper half and vice versa. The camera moves up to show the upper part when the player reaches the median and moves down too.
- the moving platforms for the upper part. I used lilypads instead of logs.
- the badgers instead of moving vehicles.
- the frog dying when falling in the river or being hit by a badger.

Implementing the moving objects was easy enough with the use of a spawner system. I implement a spawner that's able to spawn any type of moving object. good or bad. all moving objects in the game have the same behaviours so it was easy enough to implement. The behaviour scripts of any moving object that I want to spawn inherits from a base class called MovingObject which has direction and speed variables with monobehaviour functions as virtual so any similar behaviour can be accessed by any class or script that inherits from MovingObject.

The movement behaviour is the same on any moving object, moving from left to right or right to left. the update is called only once in the base class virtual update and every class that inherits from it will move exactly the same way dependent on the direction variable. So in the spawner, the direction and speed variable is set before the moving object is instantiated.

I created a factory of moving objects so that the spawner can just grab an object from the factory that needs to be spawned. this will make increasing the difficulty of the game later on  by just controlling or randomizing what type of moving objects will be spawned with a speed and direction.

After finishing the spawner system for moving objects, I started to implement the moving platform behaviour for the lilypads and the frog which was not part of the checklist but I did it anyway and I'm thankful actually to have started early on the moving platform because implementing a moving platform and making sure that the player does stay on the platform took time because of me wanting to try what might work best for me.

After about to finalize the moving platform behaviour, I found out that OnTriggerEnter2D and OnTriggerExit2D does not work as intended. I read on the forum that the 2D trigger functions are still buggy. OnTriggerEnter2D works like OnTriggerStay2D - which means its always called and OnTriggerExit2D doesn't even get called. Because of this I had to redo all my collision on the game from 2D to 3D collisions.

I also have to move from X and Y coordinates to X and Z, this is so that  I don't get confused with anything from collision to position since I'm dealing with 3D and not 2D. It's just my preference mostly, if working in 3D, I use X and Z (forward, back, left and right). It makes sense for me.

I made all sprite animations a child of the game object itself, for example the player gameobject parent has the colliders and movement script and the child has the player sprite animation and animation scripts. any player behaviour is done on the parent and animation behaviour like transitions is done on the child. I did this to all game objects that I have currently. That's a lesson learned at least. For now 2D triggers are not working. I don't know if it's been fixed but I'll stick to 3D.

As of Day 2 the frog  can hop onto the lilypads and die when it falls off, the frog can die when colliding with a badger. Hopefully, no more big problems will arise later on, but I'll expect more problems to be tackled. I' moving onto Day 3.

- Frog home
- Frog lives
- Respawning
- Additional moving objects - snake, bunnies with arrows, a rock

Here's a video of the game for day 2

No comments:

Post a Comment