Collision: SlapEngine at Work
Collision for the SlapEngine is actually not that bad. We have either wrapped our objects in a capsule, sphere, or AABB. We test each geometry against the other in order to determine collision between two objects. The only thing that we have different from that is how we determine if the Entities are in bounds of the game world.
Entity Collision
Entities are the Player and Enemies. For each entity, they have a body capsule around their body and spheres located on their feet and hands. The body capsule is just two spheres connected by a line segment. The first sphere is 5 units up on the Y-axis with a radius of 5 unit from the entities model location. The second sphere is 5 units down the Y- axis with a radius of 5 units as well. Then simply, we create a line from the first spheres center point to the second spheres center point. This gives the entity a non-rendering capsule around the entities body. Here is an example:
Once we set up the body capsule we run Capsule To Capsule tests against other entities. If the collision comes back true we just negate the velocity of the entity. This gives a smooth collision reaction force for the entity.
Combat Collision
Combat is handled by adding spheres to the hands and feet of entities. The hands and feet are the only things that will be swinging at others to cause damage, naturally. So, we put spheres on each bone location of the model. A sphere is just a center point with a radius. When we load in a fbx model we just find its bones then determine which one is the hands and feet. Once found, the center point for the spheres is just the bone location in 3D space. We can then tweak the radius to determine what size the hit collision should be. The larger the sphere the sooner the collision. Once size is established, we do Sphere to Capsule test against the hand or feet sphere and the receiving entity's body capsule. If the collision comes back true, we deal damage to the receiving entity. Here's a visual example:
Static Object Collision
Things like desks, pickups, weapons, and any static environment objects are wrapped in an Axis-Aligned Bounding Box. They are simple primitives with a min and max. The AABBs have to be custom fitted to each object unfortunately. The bright-side is once you fit a Desk with an AABB then all desks with be fitted properly. The work is not too bad. From there, we run Capsule to AABB tests to determine collision between an entity and an object. If an entity collides with the AABB then we negate the entity's velocity.
In-World Bounds Collision
Collision for keeping the Entities in the game world is a completely different beast. We have constructed a navigation mesh that is used for the AI path finding. We decided to use it for bound checks too. The navigation mesh is just a plane that has had the model's triangles combined at run time into squares. We chose to use squares because it is more easily manageable than triangles. Once we have the squares, we set up the squares neighbors. Anything that shares the same edge as the square is a neighbor. With the neighbors set, we make a list of any square that doesn't have four neighbors and put them in a border list because they are the border.
This is the basic work and ideology behind SlapEngine's collision detection. Hope this was insightful for you all. Any comments or concerns? Let us know. Thank you.

Comments
Post a Comment