I want collision boxes to be precise without overlapping each other

134335-capture.png

I want the player’s movement to be very precious, but without collision boxes overlapping each other. Because with overlapping, the player wouldn’t be able to move forward (I have set it so that player has a velocity of 0 if they ever hit a collision box). Keep in mind, my player moves like how tiles in 2048 (game) works. Any advice are appreciated. Thanks in advance! :slight_smile:

You aren’t going to get that level of precision with the physics engine as is. There has to be some level of overlap (however small) because of the way collision detection and collision response is handled. Furthermore, relying on floating point numbers with distances that small is not a great idea, as you will probably get some precision issues anyways.


However, if your player is supposed to move in a fashion very similar to 2048 tiles, then you don’t need to use the physics engine in the first place. In fact, it would be over kill to do so. You would be better off storing your level data in a 2D array of, say integers where the value at some position in the array tells you what kind of tile is at the position. When you want to move the player, you can check for tiles that are impenetrable in the direction of travel. If a tile exists that the player should not be able to move through, then you do the entirely obvious thing of… don’t move them.


With that being said, you would also need to store the player position as a pair of integers so that you can quickly index the level tile data to check for potential collisions.


Obviously this is more work than just dropping sprites into the scene, but it will get you the level of precision you want in your moment system, and separate you from Unity’s physics engine and allow you to implement your own behaviors.