In-Depth Blog Post #4

Progress Report:

In the past few weeks, I have made a lot of progress in the creation of my game. I have added a slew of new features, such as new enemies that pathfinds toward the player, melee attacks, and sprite animations. In addition, the player will now always face the direction of the mouse. With the addition of these different game mechanics, I have learned many valuable and useful techniques to implement in any later projects, such as how to animate sprites, how to create melee attacks and physics-circles, how to scan within those fields, how to use A-Star, how to find the position of the mouse cursor, and how to find the direction of the mouse cursor relative to the player. The mouse cursor direction part is especially useful, because it an extremely common way to allow the player to aim. A-Star is a great way to make your game more dynamic, and it allows you to make NPCs that react to their environment, instead of robotically moving in a pre-determined series of actions.

You may remember from my last blog post that I had a lot of trouble with the melee attack. Well, I fixed it! With the help on my mentor of course. It turns out, creating a melee attack is much more difficult than one might expect, and requires a plethora of different moving parts. The first problem in my original attempt was that I was using a function for 3D games, instead of 2D. I was making a sphere instead of a circle, which the 2D game couldn’t process, yielding zero results. The following steps require many other components and mathematical processing in the code. You must find the position of the mouse cursor, create an angle around the line to that point, and scan any entities in the newly created field. Then, you need to make the player code send a message to anything in that field (if there are any) and modify the affected object’s code (in this case, the enemy) to react to that message in a fashion of your choosing. In this case, I created a stun effect on the enemy whenever they are hit, as well as some knockback. Later, I will add a hit points mechanic, so you can eliminate the enemies, instead of just pushing them around. Finally, I created a player animation for attacking, which is a punch/swipe in front of them.

What is pathfinding?

Essentially, the enemy scans the map, searching for any obstacles, then finds the shortest path towards the position of the player. This function can be done in many ways; one such method is an A-Star algorithm. My mentor suggested I use A-Star, but since creating an A-Star algorithm of my own could be its own separate in-depth project, he suggested I use an online A-Star algorithm. I downloaded it and imported it into my project, and I used an online tutorial on how to configure it. But there was a problem. The enemy kept getting stuck on corners but could easily navigate a flat wall. It took some time to find the solution to this conundrum.

The base of the problem lies within the way it finds it way across the main path it finds to its destination. It draws specific points along that path as little mini destinations, to lead it across the path.

The problem was that I set the draw distance too far away, causing it to draw it past the corner. Since the enemy always tries to move directly towards the draw point, hitting the corner, and getting stuck. It took an embarrassingly long time for me to realize the issue here, and the solution was extremely simple: just turn the draw distance down, and it will draw its next destinations right in front of it, allowing it to move around corners instead of trying to move through it.

What will I add next?

My next steps shall be to add projectile attacks to both the player and enemies, as well as melee attacks for the enemies so they don’t just push you around. I will also add health mechanics, so have incentive to evade the enemies, and have a way of disposing of the enemies.

 

Reflection Questions:

  1. What has been your most difficult mentoring challenge so far?  Why?

The most challenging thing is probably frustration. When I have a problem and cannot figure it out, especially when I am very passionate about it, I tend to tunnel-vision on it and stubbornly refuse to do anything else until I fix it or give up. These ends up wasting a lot of time, as the problem could easily be solved by my mentor’s experience, and the many simple solutions to the problem. Since the last blog post, I have improved in leaps and bounds in this respect.

  1. What is working well? Why?

So far, I have implemented many of the game mechanics into my game, and I am feeling quite optimistic about how much of my goals I will achieve. Thanks to a few tricks my mentor taught me, many game mechanics have been easily added to the game with very little trouble. I think that my game will be quite complex by the time I’m finished with it. In addition, because my mentor is with my dad, I have an abundance of opportunities to learn from him, and our schedule is very flexible.

  1. What could be working better?  How can you make sure this happens?

I could think of anything I would like to add to my game, for example, projectiles, and tell him what I would like to add before the lesson, allowing him some time to think of a more structured lesson plan and any techniques he may forget in the moment. This would allow our lessons to flow more smoothly, as well as make them more efficient. Hopefully, with this in mind, I can go even further beyond my expectations.

In case you would like to play, here is a link:

My game

To play, download the zip file.

Then, unzip the folder, and go into InDepthGame > InDepthGame > build > windows > x86~64 and double click on InDepthGame.

If it is blocked by your firewall, just click allow.