Godot Version
.NET/C#, latest
Question
I would like to implement a 2.5D movement system, and I would really appreciate some guidance, so that I can avoid scratching large parts of the code-base as I have done a few times before.
The premise is as follows:
Outside combat, the character can move in eight directions. Characters can collide with objects and slide around them if needed. Overall, the movement would look similar to Triangle Strategy in this trailer here.
When in combat, the game would turn turn-based and a visible grid would appear on the level (think Heroes of Might and Magic combat). In other words, all objects on the grid (arena) must end their turn on a single given tile and only move from cell to cell (in 8 directions). Collision shapes now become less important (or not important at all). However, the movement should still be smoothly animated and preferably look the same as that of outside combat.
Since I’m operating on the tile-map, I thought it’d be easiest to always stick to the map position.
Now, in combat, if I move a player on the grid by changing its Position
property and calling LocalToMap() so that I get the coordinates on the tile map, then the movement will become snappy and more difficult to animate.
For instance, I click my cursor on the tile, I get the tile coordinates (e.g. [0,1]), use A* algorithm to find a path between the starting position and an end position (e.g. [0,0] → [0,1] → [0,1]). This way, the character will only ever find themselves at these three coordinates, effectively teleporting, so it’s not easy to animate movement.
I understand I could try to interpolate the position somehow using tweens
but still, if I change the position by updating Position
property it will probably be a bit more difficult to do, and then I would also lose the ability to re-use the movement system for outside combat, because detecting collision now becomes way more difficult.
So essentially, I think I need to move using MoveAndSlide()
both in combat and outside combat. But now in combat I need to somehow snap the character to grid so that, for instance, if I use my cursor to click somewhere on the grid, the character ends up in the middle of the tile and not, for instance, in between the tiles. And so that it does not move in between/on the borders of the tiles either (only in 8 directions, always in center). But then how would that work with pathfinding? Do I then path-find without using tile-map coordinates but local ones?
How would you approach it? Should I drop the idea altogether and just implement two separate movement systems?
Again, any tips would be much appreciated