470 Sprint 3
Work Completed
For this sprint, I worked on the AI and introduced a new state and further implementation to existing states. I created a defend state where the AI would guard a certain area it was assigned to after reaching the idle state. This way the AI would do more than just standing in one place if it was not chasing the ball or player. This meant that I also added to the idle state so that the AI would return to its defensive position and then enter the defend state. Another thing implemented was the AI shooting the ball and adding an accuracy range to the shots so that not every shot would be exactly where the hoop was.
As shown in the gif, the two opponents playing in the backcourt and going side to side in their defensive area and the opponent at midfield is chasing the ball.
For the defend state, the AI can go back and forth between two points and it will change states if either the player or the ball enters their range. The distance the AI patrols, it can be changed through the defend range variable in the defend state script, but this is added so that the AI can still move around and give the player an added layer of difficulty when trying to score.
In order for the AI to enter the defend state, it first needs to be in the idle state. This may be renamed later to the reposition state, since the AI will now go to a specified location if the ball or player are not in range to chase. We didn't want the AI to just stand on the field if no objects in range, so we decided that the AI will go into a defensive position on the court. This adds to the gameplay experience because in a real sports match players aren't just standing around, so we wanted to emulate a more realistic opponent AI. Once the AI is at the defensive location, it will enter the defend state where it will carry out the functions stated prior for the defend state.
Here at the beginning of the gif, you can see the application of the idle state. The AI will move to it's designated defensive position, and then it will move back and forth in the defend state.
Another obstacle that was solved this sprint was the implementation of the AI shooting the ball and the shot having an accuracy range so that not every shot made it inside the hoop.
How this worked was that the AI added a force upon the ball's rigidbody in the direction of the hoop. The appropriate hoop was assigned to as the reference for the target goal transform and then the ball would travel to this point. This worked well for making a shot to the hoop no matter where the AI hit the ball, but we felt that the AI shouldn't be making every shot because it would be too difficult for the player to keep up with the perfect shooting AI. What I did was create a shot variation float variable and then multiplied it by the Random.insideUnitSphere function that is a UnityEngine class. Then, I added that value (+=) to the hoop direction, which was the position from where the AI interacted with the ball and the hoop position.
In the gif, you can see the AI hitting the ball and the ball going in the direction of the hoop, but not completely at the same direction. This range of accuracy can be lowered or highered, depending on how much challenge we want the player to face when playing the AI, or depending on the difficulty the player chooses.
Comments
Post a Comment