Week 4 (Movement, AI & Sprite Origins)

This week’s focus has solely been on the completion of the alpha stage of the game. The team split up the remaining things that needed to be done and hastely started to crunch some code.

The elements I had to fix/create was a movement fix due to the group getting a lot of comments about it feeling a bit of odd and difficult to manoveur, a sort of AI for our first enemy named the Prowler and fixing so that all sprite rotation origins were in the middle of the actual sprite.

First thing I decided to dive head first into was the movement fix. I was responsible for the last movement, so I had quite a bit of knowledge on how to make it better. While the last movement we had rotated and moved at the same time when holding down any button. The new movement system use A and D for rotation and W and S for forwards and backwards.

The first problem i encountered was that I didn’t exactly know how to get the ship to move the way the sprite was pointing towards. My fix for this was to use  an equation that included sinus and cosinus that calculated the degree the sprite was pointing towards. However, the ship didn’t move towards where the sprite was pointing, but to the side of the sprite. I fixed this by taking the initial equation divided by 180 multiplied by PI. Which rotated where the ship was pointing to where the sprite was pointing visually.

Second thing I had to do was to create a foundation for the future enemy AI in the game. Since it only needed to be simple all I decided to do was that if the player went closer than a certain amount towards the enemy, the enemy would aggro (meaning it runs towards the player). If the player then successfully managed to run further away than another amount the enemy would drop aggro (meaning it would run towards it’s original position before aggroing towards the player. However if the enemy managed to get within yet another amount of distance the player would take damage, resulting in the death of the player.

How I managed to do all of this is quit interesting. Firstly I wanted to get the distance between the player and the enemy. I used the pythagorean theorem to get this distance. (x^2 + y^2 = z^2) and then told the game that if that distance would go above, or below a certain number the enemy would either aggro , drop aggro or kill the player.

Last thing, and the least interesting thing I did this week was to manually fix all the wonky sprite origin points, since most but not all pictures middle point wasn’t the actual middle of the sprite in game. So all I did was looking up the exact point in a photo editor (paint, pixlr, photoshop etc) and then put in that point as the sprites origin. I did this for 5 different  sprites and it took longer than i expected since getting it pixel perfect was only achieved by trial and error.

64e48f4abaa1fd6795f6e0db844ca6d0

One comment

  1. Anton Olin · February 23, 2016

    Well written blog post which gives anyone interested in solving the same issues as you, a good idea on how to solve them by themselves. There is not actually much to point out as it looks like you have solved the issues you were currently facing. However what could be improved in the blog post is to only focus on one artefact at a time, since this is the actual task given by the teachers. This also makes it easier for anyone that tries to learn and understand from this blog post in the future. to know what is being discussed and described in the text without actually having to read the whole post. It would also be interesting to know how the movement was programmed before and what has been changed. Why was the old movement function bad? Why did it need changing? and so on. If this could be described more thoroughly, a person who in the future is looking to learn from this blog post, would probably be able to benefit a lot more from it.

    But as I said in the beginning, still a very well written and good blog post. Just think about the things I mentioned above in the next blog post.

    Kindest regards,
    Anton Olin

    Like

Leave a comment