This week, I got some basic movement code done and the basic framework for being able to increase the speed of the game.
I forgot to actually finish a decent theory writeup so I’m making up for it for showing the First Footage (that’s underwhelming).
Movement
Bevy is a pretty barebones engine that doesn’t include things like basic movement code or the like, so I had to implement them myself.
It wasn’t too difficult to whip up a smoothed movement system. This is probably a really dumb way of doing it but the final algorithm I settled with almost emulates manipulating a joystick.
A normalized 2d vector is used as the “input” vector, and then that’s multiplied by speed which is turned into a velocity that’s applied every physics step. Entities move by being given a “target” direction, and then the actual applied direction is gradually smoothed towards the target.
It’s actually only two lines:
movement.current_direction = movement.current_direction.move_towards(movement.target_direction, movement.accel * time.delta_seconds() * gametime.time_scale);
physics.velocity = movement.current_direction * movement.speed;
There’s some extra delta time nonsense as well but the underlying logic is just “move current direction towards target direction, and then set velocity to direction times speed”
It’s a little janky and not super precise, but it ended up producing pretty smooth looking of movement. From there, it wasn’t too difficult to implement a system for moving towards points as well as a companion system for moving along provided paths.
All of these systems are delta time based, so every frame they get passed a delta time. I assumed the easiest way to make these have adjustable time scales was to just multiply the delta time by the timescale which…
Well…that’s not right. At first I thought it was just the system wasn’t going to scale, but I pretty quickly realized it was actually just that the input smoothing needed to scale as well
There’s still some imprecision but it definitely is a lot closer to what is intended. Even scales up pretty well
There’s still quite a large amount of end position imprecision at higher time scales though. It’s really obvious with mass movement because you can see how much more spread out the final result is.
I probably need to implement some kind of approach slowdown for target points so it doesn’t overshoot them so much. Or maybe rethink the problem all together. This will work for now.
This will be super easy to plug into an actual pathfinding system, because all you have to do is provide a list of vectors and the entity will move along the path.
From here I’m probably going to start working on very basic construction so that basic needs and things that fulfill them can be put in.
Next week will be about AI systems.