AI Chase and Shoot behaviour
For the last week, I've been working a little bit on hitpoints, damage design, detection sphere, AI behaviours along with related class design and a bit of enemy indicator on the screen space. Truth to be honest, it's whole level of difficulty and headache, but I would like to think that I feel like I have made a very tiny little progress in term of knowledge in game development. So many physics and maths going around.
Hitpoints and damage design
So far it's pretty simple mechanic, and i am not yet planning to work more on this yet. The damage is taken from a calculated energy information stored in the every projectile shot at a target.
AI Behaviour
I was actually trying to figure out the homing / guided projectile mechanic, and somehow I need to at least have a simple enemy AI flying in space. Just didn't realize that I need to tackle this AI related problems soon enough.
So far we have only two AI behaviours, namely the patrol and the chase behaviour.
A simple patrol behaviour code
What I think I am starting to like is, the polymorphism design i managed to implement initially in this project.
So in our project, we'll be mainly working with an abstract mono behaviour component called
BaseShipController. So instead of implementing the AI behaviour throughout this component or as a separated component, we'll instead have it (BaseShipController) work with the interface called IFlightBehaviour.IFlightBehaviour usages
Neat right. So, this thing is called Interface Segregation Principle (ISP), per I in SOLID practice. The behaviour will only be performed whenever it's available. Not only that it reduces code, and decouple things, it also should de-allocate any unused works.
.
The other behaviour I've implemented is the Chase Behaviour.
Chase and attack behaviour
Also, it's quite simple. The only headache i had with this one, is probably to figure out when to start shooting. I was thinking that the only time to shoot will be when the AI has fully looked at the player. So, the mechanic we're actually working with is the rotation of the AI and the target rotation (the rotation to be rotated to). Since the rotation process wasn't instant (we're using Quaternion.Slerp for that), it need a point where it can start shooting. Because it can't shoot all the time, and not only when it has fully looked at the player (because it'll probably be never). So, we need some sort of angle for that, and there you go. 5 degree between a the current rotation with the target rotation will give you permission to shoot.
Enemy Indicator
This one is probably another headache i am failing at last week. So unity has three kind of canvas render mode namely; Screen space - Overlay, Screen space - Camera, and world space. I think I've managed to map the 2D location of our enemy to the screen when the mode is set to overlay.
Enemy speed indicator
One thing about this render mode is, the indicator is still showing in front of our ship when it overlaps. I've tried the screen space - camera mode, and it gives the nice result i want to. But pinpointing the 2D position by the world position seems to be problem at this point. Plus, I checked another game called Sky Rogue, and I think they're also using overlay mode. So, for now i guess is ok I think.
Detection Mechanic
Detection sphere
So, i am using a unity collision mechanic, that whenever our unit entered the sphere, we'll some sort trigger the chase behaviour (for now) if the detected unit is a player.
Still I can say, I don't think it's a lot of progress last week. But with the AI behaviour interface implementation in place, hopefully we can see more AI and the awaited homing projectile next week :).






Comments
Post a Comment