Trouble with knight

The beta release of our project is next week and we have been working hard with implementing all our assets into the game. I have been having a lot of trouble with the knight due to not having a clear vision on the code. The knight as a whole consists (or rather, will consist) of a sweeping attack, a shield that blocks damage, and a charge attack, and then of course an AI that ties this all together and executes the code. The AI will use Unity’s animator as a statemachine, due to timelimits on making my own statemachince, and why make one from scratch if the engine has one built in. Using the animator as a statemachine works here since all the states will have different animations.

As of now only the charge and sweeping attack are working, both needing some fine tuning. The shield is also there but it doesnt really do anything apart from just block damage, I want to make it bop with the movmement and be put to the side when the knight attacks. There is also no proper AI as of the moment, so I can either enable the knight to be in “seek and attack” state or just “charge when possible” state.

The charge took a lot of trial and error to get to work, because I couldn’t think of the logic I should use for stopping the charge. The check for starting the charge was a matter of raycasting and checking distances and cooldowns, the charge itself just disables rotationspeed and increases the movement speed,  but I just couldnt figure out how to stop the charge. At this point I had a mess of a script with 300+ lines of code (more than half of it being commented out) then I finally discovered a method that might work. this was to check the Knight’s position before it starts charging, then check the distance to that initial position and stop the charge after a set distance. However as my script was a complete mess I just decided to scrap the whole thing and rewrite it completely, and finally achieved results I wanted.

The charge can be seen below:knightCharge.gif

Now what I have left to do is finish the statemachine and AI, so the knight will actually know when it should charge/attack/move/block. I also need to actually, add functionality when it hits the player, right now it will just push through. We were also talking about having a small stun after it charges (and misses).However, I’m feeling fairly confident that I will complete those in time, as this charge was just like hitting a stonewall, but now that i have cleared it I can move on with fresh code.

About Leevi Hakala

2016 Programming