8void Walk(
const Terrain& terrain,
float& x,
float& z,
float to_x,
float to_z) {
12 }
else if (terrain.
Walkable(to_x, z)) {
14 }
else if (terrain.
Walkable(x, to_z)) {
20 float direction_z,
bool run,
float seconds) {
24 const float length = std::hypot(direction_x, direction_z);
26 direction_x /= length;
27 direction_z /= length;
30 const float edge = terrain.
edge();
32 std::clamp(x + direction_x * speed * seconds, -edge, edge),
33 std::clamp(z + direction_z * speed * seconds, -edge, edge));
float edge() const
Half a metre short of each side, so that players stay on the grid.
bool Walkable(float x, float z) const
constexpr float kWalkSpeed
In tiles a second. A tile is a metre, and walking is the walk clip's speed.
constexpr float kRunSpeed
void Walk(const Terrain &terrain, float &x, float &z, float to_x, float to_z)
void WalkAlong(const Terrain &terrain, float &x, float &z, float direction_x, float direction_z, bool run, float seconds)