So I’ve basically built a level out of 64x64 tiles, each tile has it’s own collider. For example, the flat ground tiles are just plain box colliders, and so I have used the scene view’s vector snapping function to line them all up neatly. Problem is that even though they’re neatly lined up, the fact that they’re separate box colliders gives the player bumpy movement when running along these aligned tiles.
A quick fix is to just set the y velocity to 0; however when the player moves down a slope, this cannot be zero, and I haven’t found a way to set a ‘relative y velocity’ to zero.
Another idea would be stretch a single collider over a collection of tiles, however this can get inconsistent with the position of the tiles.
So does anyone have any suggestions on how to counter this issue?
Okay, so I’ve come up with a solution. Just made a script that is attached to a basic shape (say, a square), and if I want to make a long flat plane then I increase it’s local scale and instantiate tiles along it based on it’s scale.
So if a standard 64x64 block has a localscale.x of 3 (so I want it 3 tiles long), I instantiate tiles using a while loop so that when i=0, it creates one at origin; when i = 1, it creates one at 0.64 to the right of the origin’s x and one to the left. Also it’s adjusted for a localscale.x that’s an even number so it creates on at 0.32 to the right/left of the origin’s x.
And of course if the tile is a slope then the y value has to be adjusted too.
As a result, the (one) collider is just on that basic shape that stretches across the tiles which are just plain sprites. Problem solved!