godotrecipes / 2d_grid_movement

MIT License
10 stars 3 forks source link

Concurrent Movement #5

Open nightblade9 opened 1 week ago

nightblade9 commented 1 week ago

Hi,

I've been looking for a Godot starter/sample code that solves the problem of concurrent animated tile movement.

If you have a tile between you and a monster, and both of you intend to move to the same tile at the same time, one should move and one shouldn't. How can I accomplish something like that, with his code?

I tried a couple of approaches, but to no avail; what's that's the right approach? Any suggestions?

What I tried:

nightblade9 commented 1 week ago

If anyone else is looking for a solution to this, there's one here, with very minimal functionality: https://github.com/deengames-prototypes/roguelike-base/tree/299d0f6d4bc6e2a7b4701941177744c0f0be5607

TL;dr all entities inherit from a base BaseEntity class. It has a static Array2D that clears each turn, and keeps track of who is going to move into what spot. When things move, they mark their spot in the array, and right before moving, check if that spot is still available. If not, they back off.

Simple, clean, and works fine (other than static variables which are global state which I hate). Good enough for now, considering I've tried (and failed) several times to solve this problem cleanly and simply.