[3] Movement And Follow Refactor

06/20/2019, 04:02pm

Not much to report today, because I have been refactoring.

I modifed the server-side movement code (as I mentioned in the last dev log) so that movement packets are sent a bit more frequently in order to allow characters to follow other characters (for combat) or even follow a totally different type of entity (that's the power of ECS, baby). That stuff worked well, until I ran into another issue I had anticipated, but was waiting to see in action.

My original method of handling movement was to add some velocity to a Character's position every tick, and when the destination was very close (within 0.25 units) the character would snap to the destination, and end movement. This works well for most games, but most games run at an actual speed (like 60 frames per second). This game loop runs at 2. Even with a delta time, it resulted in situations where characters were overshooting their destinations, then overshooting again when they tried to correct themselves, resulting in them getting stuck in a twitchy loop. Movement was not deterministic enough.

To fix it, I just reworked the movement system to work based on a move start tick and a move end tick. Since I know when a Character's movement started, and when it should end (because the tick rate is constant and I know the movement speed), a progress percentage can be calculated, and then the characters current position can be calculated with some vector math. Voila.

Now that these refactors are out of the way, This evening I'll spend some time getting back to the combat implementation. Every time I test combat, I need to restart the server to reset the NPCs. I want to fix that and get some primitive death/respawn mechanics in. For now, when a character dies, they should just respawn immediately at their initial spawn point.