Unity end-of-term AI football game project (free and open source)


The game project is for reference only, and the download link is at the end of the article. If you need to answer the essay, please chat privately

Version: Unity 2018.4.36

game introduction

Crazy Soccer is a fun soccer simulation game. Players will see the autonomous battle between two teams, and improve players' awareness of football by watching the exciting competition between AI teams.

This game project aims to skillfully practice and practice the relevant knowledge of game intelligence learned in class. The main technologies involved are: AI behavior tree logic design, countdown function, scoring system implementation, data storage, and a series of UI interaction and animation special effects production.

overall framework

insert image description here

partial screenshot

insert image description here
insert image description here

insert image description here

Screenshot of answer essay

insert image description here
insert image description here

Defense question

1 How to realize the countdown function?

Use coroutines. Usually, the countdown function is implemented with the Update function. However, due to frequent Updates, each second is equivalent to performing multiple countdown calculations, and the performance overhead is too high. So I thought of using a coroutine to implement the countdown: call the statement in IEnumerator: yield return new WaitForSeconds(1f), that is, it is only updated once a second, not every frame. The total time is set to 60 seconds, and the total time -1 for every second that passes. When the total time is 0, set timeScale to 0, the effect is that the functions based on the frame rate will be suspended, that is, the screen will be static, and "GAME OVER" will pop up, and the game will end.

2 Where is the realization of AI?

Embodied in the goalkeeper's AI behavior tree logic, the AI ​​logic I designed is: ①The goalkeeper first patrols near the goal, but the goalkeeper always faces the direction of the football (Repeater+MyPatrol+RotateTowards+Parallel node, Parallel is used to concurrently execute goalkeeper orientation and patrol) ②If the football enters the field of view, then chase the football (Seek+CanSeeBall+Seek node, set the interrupt type of the Sequence node to Low Priority) ③Catch up to the football and kick forward (Seek+Shoot node. Seek automatically ArrivalDistance is defined, that is, what distance is set to indicate contact with the ball, and success is returned when contact with the ball, and then the forward kick behavior is performed. The Sequence node is set to Low Priority) ④ If the ball is no longer in the field of vision, continue to repeat the first step step-by-step patrolling behavior.

3 Implementation of the scoring system?

The first is to place a collider inside the goal to trigger the goal event. After a goal is scored, the score of the scoring team is increased by 1, and then the scene is reloaded. Scoring uses delegates and events: define a scoring event, which is used to send a scoring message. After a goal is scored, the scoring event message is sent, and the parameter 1 is provided for the receiver to achieve +1 point effect. After reloading the scene, in order not to initialize the score and countdown, a data class is defined in the singleton mode to store data, mount it on an empty object, and set the empty object so that it will not be destroyed when the scene is initialized. .

Download link
https://github.com/Curzsu/Crazy-Soccer

how to download:
insert image description here

Guess you like

Origin blog.csdn.net/m0_56494923/article/details/130604349