2D Platform movement and physics based on a Tile-grid world.

So I have started a project where I create a world by a two-dimensional integer (int[,]), I then add tiles based on white noise + cellular automaton (so int[x,y] = 0 if empty, int[x,y] = 1 if occupied). The grid-coordinates match up perfectly with the world coordinates (since I use 1x1x1 cubes as tiles).

I now want to add movement and physics for an AI. I’ve tried Rigidbody (I get the physics), but it doesn’t seem to work too well with scripted movements, since when moving (with MovePosition()) it ignores physics, and when adding force I can’t really say “Move to tile[x+5,y]” (and btw, remember to check is there is ground beneath you, before you move to the next tile) and then make it stop at exactly that position (even when using rigidbody.velocity = 0, there are possibilities for overshoots).

I tried the character controller, but it doesn’t have built in physics, so I just started doing my own implementation instead. What I did in pseudocode was “if the block beneath you is empty, Vector3.MoveTowards(emptyblock)”. and added that to my Update(). The problem here is that any other movement doesn’t take the “gravity” into account. When a new “MoveTowards()” is called it seems to cancel any other “MoveTowards()”.

Does anyone have an idea or know a paper on grid-based movement with physics?
Anyone know how I could implement my own system without MoveTowards()? Is there a better function to use?
Which system would you use?

I started getting somewhere by adding all my movements to one vector, and then only call MoveTowards(thatVector) in my Update().

Would still appreciate a paper/article on the subject :slight_smile: