Player Movement Issues

During testing the majority of people came back with feedback about the movement not feeling right or satisfying. One of the main reasons was people found that the player character would get caught on the ground at seemingly random times, they could go for a few minutes without any issues then all of a sudden get caught every few feet.

Another issue I had with movement was that when running too fast the player could clip through walls and jump through the ceiling. To fix this I had to look at a different method of moving the player, using .velocity instead of addForce() to move the player. This stopped the player from clipping through geometry as the rigidbody on the player does most of the work.

Ground Stick Fix: part 1

To look into getting caught on the ground tiles I searched through Unity forums to find multiple people having issues with 3D tiling. Due to an issue with the Unity physics engine, moving rigidbodies would sometimes have an issue where between two box colliders, the engine thinks that the player collider is moving towards a box instead of across a flat surface and would get caught in between the two colliders. 

As my level is made up of multiple meshes with box colliders on, it meant that the player could effectively get caught on any floor surface when running and generally the faster they moved the more often it occurred.

One of the fixes that people said was to use edge colliders instead of a box as it meant that there was no ‘edge’ between the two flush box colliders. This could have been a good solution but unfortunately edge colliders are only available for 2D. 

Another potential solution I found is that in the physics settings for Unity you can change the distance/amount of calculations that the physics engine calculates. I lowered this value so that the engine would be more precise and while it seemed to work at first I quickly found that it was still an issue.

The current solution I’m using is to effectively create a very small gap between the colliders instead of having them flush. For some reason this seems to prevent the strange physics calculation issue as it appears to make it easier to distinguish between the two edges and because the gap is so small the player cannot get caught on it.

Ground stick fix: part two

I disabled the player box collider and added a capsule instead. For now it seems that the capsule is less prone to getting caught on the edge of the floor colliders due to having a smooth edge as opposed to a sharp cornered edge. This meant I could revert the changes made to terrain, effectively fixing the enemy movement issue mentioned below.

Enemy movement

Initially the enemy movement script seemed to work, with the enemy stopping at the edge of ledges. However, because of the initial player movement fix I used to stop them getting stuck on the floor tiles, the enemies then got stuck instead due to their script detecting a small gap between the tiles.

With the player movement fixed, the enemy movement was fixed for the most part, stopping at the edge of ledges. However in some areas of the level, the thistle ball enemy would go through walls and in one specific case, get pushed through the floor due to a stalactite collision box. To fix this I added an extra two layer masks (a layer mask being a way to distinguish a specific group of objects) to the enemy movement code to check through a total of 3 layers, if what it is touching comes back from those layers then it moves back in the opposite direction.

Leave a Reply