ARTIFACT BLOG #3 Our second enemy

Greetings!

Chosen artifact of the week is the ranged enemy for our game. The behaviour we wanted for it was that it should be passive until attacked by the player (You *have* to kill all enemies to win so they’re not skippable) and when it’s in its attack state it should start to zig-zag rather fast while shooting at the player. And as of tonight we’ve pretty much nailed the behaviour.

We started off by making the enemy shoot against the player all the time (enter any if-statement that is always true) as well as make the player change color when it got hit, just to check that it worked. After we had the actual shooting part completed we wanted to change the if-statement to only when the player gets too close. We solved this by putting a circle that is bigger than the enemy on the enemy’s position, and change the shooting trigger to check if the player is overlapping the circle. Which we did by checking if the distance between the player and the circle was smaller than the player’s radius plus the circle’s radius. So now we have an attack range for the enemy.

Making the enemy zig-zag proved to be a lot harder as neither Hampus nor I had really tried to make an object move on its own before. But we managed with the magic of if-statements.

enemymoving

We have a float that is initially set to zero, and it always ticks down from whatever value it’s at. If the float is lower than zero, it enters a world of if-statements. First, when entering the first statement, we set the float to 3. After that it checks if the float’s value is higher than 2.5, and if it is the enemy gets a linear velocity and starts moving downwards. Then it checks if the float is higher than 2.0 but lower than 2.5 and if so, changes the velocity so that the enemy moves upwards instead. This goes on to make a moving pattern (Down-> up slightly-> back down-> up a lot-> down slightly-> back up-> down a lot->repeat) and depending on the level design the enemy could move left and right as well of course.

So we have an enemy that shoots if the player gets within a certain range, and it zig-zags. Next thing we need to do is make the enemy only start this behaviour if it gets attacked, which should be easy enough. We just have to check if the bullet hits the enemy, and we already have a method for that as previously described in the attack range but with a bullet instead of the player.

Overall it feels rather good as we’ve done this on the exact time we said it would take in the sprint planning. Getting it done faster would’ve obviously been ideal, but it’s a lot better than it requiring more time than first planned!

One thought on “ARTIFACT BLOG #3 Our second enemy”

  1. First off I think it’s great that you’ve focused on making some interesting enemies and not just some who aims to only follow and shoot you. I don’t know what you mean by saying:” (enter any if-statement that is always true)”. Do you mean that you’ve temporarily made the condition always return true during the testing phase? I think that some parts of this post could need some proof-reading.

    The first thing I noticed about the attached image is that you’ve got multiple if-states which all do the same thing and that’s a bit redundant. Instead of writing the same code you should separate each statement with the “or” operator (“|| “). Or even better, you could make use of the math function sin(X) in order to have a smooth transition between different directions. That would also be much less code.

    Next time you write a blog post, I’d suggest you pick a larger topic with a bigger scope, since it’s a bit difficult to comment and leave feedback on such a small part of the game. Good that you feel that you are not getting behind in the sprint planning!

    I’m looking forward seeing the final product and keep up the good work!
    ~Lead Programmer, Per “Gimmic” Johansson

Leave a comment