The 2nd assignment for the game behaviour module at university was to build our own 2D physics pipeline and implement AI of some description.
Using the Unity Game Engine for the graphics pipeline only was quite a challenge. This meant not being able to use the in-built component system it provides for colliders, rigidbodies etc... The task was set to create everything and integrate the physics in an architecture which could be re-used in many different environments.
Where to start with a physics pipeline?
As always, there was lots of new areas to learn to achieve the results I wanted. Game engines like Unity and Unreal show how an adept physics system can be utilised to create amazing things. It was only natural to aim to achieve a similar system.
The Architecture
I started with defining the physics world I wanted into separate objects and classes which would interact with each-other. There would be a world class which manages the pools of every instantiated object. The world class would be responsible for calling the updates and breaking down queries through broad phase and narrow phase. These phases were using a buffer to perform AABB checking, and then using the Separating Axis Theorem to see if any points were colliding with the shapes in query.
How does it actually work?
Collisions and Force Integration
Definitely the most tricky part was handling the collisions. After creating the manifolds, each contact point within a manifold would be solved using an impulse method for both linear and angular velocity. The collisions would be solved over a number of steps to create elastic and non-elastic effects. Finally every rigidbody would integrate their acceleration and velocity. I chose mid-point integration to get the best of both worlds in terms of efficiency and result.
Where is the AI and what does it do?
From the demo is might be clear that there are some "aliens" on the dark ship that come to life and start throwing boxes around! The large purple monsters had their behaviour built from a simple behaviour tree. By simple, I mean the tree was split into some common concepts of Selector and Sequence nodes, alongside with some conditions that tick from the root of the tree every frame. The behaviour tree I built has been adapted overtime to allow for priority with behaviours and even to add weights almost like a Neural Network.
Additionally there is one other entity which is flying around using an A* algorithm to find the player. This "alien" works with a basic Finite State Machine and will run away (find a path) to a distant location when you shine the flashlight on it.
Final Overview - Re-written in C++
The physics system I made was fully functional and quite efficient in doing it's job. I provided utility tools such as ray-casting and circle casting, allowing myself to build substantial gameplay elements. I enjoyed this project a lot and have since decided to add it to an ongoing source of development tools, where I have re-written everything in C++ and put it on my github page. I will continue to expand this source and aim to add all my personal collection of AI tools to it as well.
コメント