diff --git a/src/lib.rs b/src/lib.rs index 7acc0d9..ba07c25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,30 +69,30 @@ enum Step { Stop(Vec3), } -fn next_step(_current: Vec3, _goal: Vec3, step: Vec3) -> Step { - Step::Continue(step) +fn next_step(current: Vec3, goal: Vec3, max_step: f32) -> Step { + let delta = goal - current; + if delta.length() > max_step { + Step::Continue(delta.normalize() * max_step + current) + } else { + Step::Stop(goal) + } } fn move_units(mut q: Query<(&mut UnitCommandsComponent, &mut Transform, &Speed)>, time: Res