|
Hello, today I will write about how I upgraded my AI bees for our game. Our AI bees relied on circle colliders, but now they use line casting for detecting all kind of things, but mainly the distance to the player and if a point in the formation is empty. This new system will allow our bees to react dynamically to the player, the honeycomb formation, and the different positions the bees will have in the idle state. I made this by using the line cast which comes with Unity, and the line cast has a unique function to access game object it collides with like a regular GameObject, but it does so faster than ordinary ”GameObject.Something”. I had some significant problems at first with that all the six bees found the same point in the formation. I solved this by adding all of the formation points to an array, and when a line cast hits that point, it sets a bool (Which is called isOccupied) to true and adds the line casts name to the formation point. This method allowed me to go through the array with all the formation points quickly, and check if the bool is true and if the position has a name on it. If the game object is not in use and it has no name attached to it is open for the AI bee to claim. Only when the line cast leaves the GameObject is the bool set to false, and the name gets set to empty, this allows reusability even if the player dies and respawns and if the AI bees need to change their line casting. This method has been an incredible learning experience for me as I have started to use the line casting in many different ways. For example, finding the closest enemy, detecting the distance from the bee and if it is greater than a set distance it moves in so it can fire on the enemy and go back to is the original position or turn away if the enemy is to close.
I know I changed the topic from what I said I would talk about last week, but this was more exciting and fun topic to explore.
About Adam Olsson
2017 Programming
|