This week we worked on object collisions ensuring that objects collide correctly with other objects.
Correct Object Collision is a task which sounds rather trivial but is anything but in reality. It is the perfect example of “Easier said than done.”
Luckily for us, Unreal Engine has much of the basic collision detection elements set up for us. Unlucky however is that much of it doesn’t work as you would expect resulting in a wide variety of bugs from objects sticking inside other objects to the floating ball glitch from a previous demo. To fix these issues we tried a variety of different techniques.
First we tried to create a physics handle for held objects to have them collide when moving around as physics bodies but this led to a variety of unforeseen glitches from held objects not moving to objects slowly falling to the ground. We soon realized a physics handle would not work for what we were doing and moved on to other potential methods.
The current grab system simply updates the position of objects to their appropriate position each frame and as a result allows for the clipping of objects into other objects as no collisions are checked for. Instead however we figured unreal might potentially check for collisions of sub objects by default when they are attached to an object that has it’s collision checked for when moving. Thus we tried to have the objects attach/detach to the player when they are picked up/released. Unfortunately this resulted in objects either not moving with the player or again having the objects clip through other objects.
The final hope was to update the players collider itself to encompass both the held object as well as the player to prevent either from colliding into objects. To do this we had to calculate the appropriate positions for the objects and players as well as the appropriate size for the collider and have them update each frame.
Eventually we got this method to work. Even though the current state is not quite ideal as it creates a larger hitbox for the player to be hit and picked up from and makes the movement look a little funky it at the least guarantees collisions are handled properly.
In the future we will have to make adjustments to the movement to make it look less strange and or add animations to make up for it. As for the larger hitbox for players holding objects, this will have to be decided whether or not we want to keep it or remove it; it will come down to how it functions gameplay wise. I might be interesting to have the player be more vulnerable to being hit when holding an object but we’ll have to see. Most likely this will remain as a feature to the game as removing it will likely cost more time than it’s worth.