diff --git a/ECS/Components/PathMove.h b/ECS/Components/PathMove.h index b22fb50..22fab58 100644 --- a/ECS/Components/PathMove.h +++ b/ECS/Components/PathMove.h @@ -18,7 +18,12 @@ struct PathMove { std::vector views; }; - PathMove(double speed, Path path, Views views) : speed(speed), path(path), views(views) {} + PathMove(double speed, Path path, Views views) : speed(speed), path(path), views(views) { + // Calculate distances + for (int i = 0; i < path.points.size() - 1; i++) { + distances.emplace_back(glm::distance(path.points[i], path.points[i + 1])); + } + } double speed; float time_passed = 0.0; @@ -28,5 +33,6 @@ struct PathMove { Path path; Views views; + std::vector distances; }; #endif // __PATHMOVE_H__ \ No newline at end of file diff --git a/ECS/Systems/PathMoveSystem.h b/ECS/Systems/PathMoveSystem.h index fa90ade..5a42a8f 100644 --- a/ECS/Systems/PathMoveSystem.h +++ b/ECS/Systems/PathMoveSystem.h @@ -85,7 +85,8 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber { PathMove::Path path = pathmove->path; // Add the passed time - pathmove->time_passed += deltaTime; + float desired_distance = deltaTime * pathmove->speed; // TODO + pathmove->time_passed += desired_distance / pathmove->distances[pathmove->current_point_index]; // Shorthand for number of points in the path int num_points = path.points.size(); @@ -171,6 +172,8 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber { // Apply transform->set_rotation_from_quat(result); + + std::cout << pathmove->time_passed << std::endl; }); }