This is pretty annoying: one player coming in contact with another player, it sends the other player flying off…into the abyss. However, trying to figure out what was going on here ended up teaching me a lot about how Unity & Game Engine physics work!
So, what’s going on here?
For the movement of these player objects, I’m taking advantage of the physics system that Unity provides. This is important – this “physics” system allows us to enable behaviors like: “I don’t want my player to be able to walk through a wall”. Unity’s editor allows you to take advantage of this through defining your player, and other objects in the world (such as walls, or in this game, treasure chests) as RigidBodies.
By defining both the player and walls as Rigidbodies, we make it such that players automatically follow basic physics rules, preventing them from say, walking through the walls, and achieve this without writing any code.
With regards to the bug here, it seems like something is going on with how these rigidbodies interact with each other. What I discovered is that when one one body collides with another, a force is applied. Since I haven’t defined any friction in this world, any force will cause the object receiving that force to continue traveling. This isn’t an issue for objects like walls or treasure chests, which are given special powers to never move (which won’t work for players).
While moving like an air hockey puck looks cool, it unfortunately isn’t what I want, and it seems like I’m actually going to have to write some code to address players colliding.