Gif of My Collision System Demo

This demo shows how the collision system works, the green one enabled hit event, red one enabled overlap begin event, yellow one enabled overlap end event
Static/Dynamic
For better performance, I made a CollisionComponentType variable for each collision component:
|
|
If the component is set to static, then it would never move so the collision between it and other components would not be detected actively. If the component is set to dynamic and it moved in current update, it would actively detect whether there are any component collide with it and broadcast certain event.
|
|
BVH
For better performance further, I implemented a BVH structure for the collision system. The structure of each BVH node is like:
|
|
Considering the difference of static and dynamic components, I made two variables in CollisionManager to store the BVH info:
|
|
The staticBVH would be only built once in the very beginning of the game because static components never move. The dynamicBVH would be built in each update to make sure the info is correct.
Demo Implement
To test whether the collision system works as I expected, I made a demo as shown in 1. Gif of My Collision System Demo. In this demo, I made three different actor classes, they are used to test different collision event(hit, overlap begin, overlap end). In each class, I used delegate system to bind the function with certain event, so when certain event happened the function can be triggered. The way to do it is very similar to how you bind event on Unreal. Here is an example of one class:
|
|
What’s Next
- Incremental update the dynamicBVH to avoid the entire reconstruction to optimal performance;
- Find other code logic that can be optimized and fix any potential issues;
- Attempt to create a visual interface to enhance the user experience
Collision System Demo
Download and have a try: MyGame