The Complexities of Prediction

As some of you may know, grades are improved if extra features are implemented. Therefore I decided to make a thing (I called it predict-o-bot) that predicts where the ball (it's actually a cube but whatever) will be and move accordingly. I did this to get good grades (also cuz its fun).

Firstly I used a while loop which ran an imaginary game inside the cpu which calculated where the ball was gonna be. To do this I made a vector3 called iBall. I also set up 2 bool variables called iDirectiony and iDirectionx. Since the ball always moved in diagonals I could have true mean going positive in its direction and false mean going negative in its direction. This was very efficient which was vital since this calculation had to be done every frame. I then put in 2 switch statements which checked the iDirection variables (they were switches because those are faster than if statements). I put increment and decrement operations for the iBall variable inside these switches. The while loop was set to end when the iBall reached the ai's paddle. After that I could move the transform of the bot towards the iBall.y variable.

In reality it took a lot more bug fixing to get this to work but after a lot of forcequitting unity since loops have a habit to run forever if coded incorrectly I got it to work. I hope this helps you understand how I think when I code :3

Warm Robotic Wishes

/Cleopatra

Go Back