From a985070f9e8e8373ef92b58fdfcc53ca59d29521 Mon Sep 17 00:00:00 2001 From: muyanzhou <139620692+muyanzhou@users.noreply.github.com> Date: Sat, 20 Jan 2024 22:58:29 +0800 Subject: [PATCH 1/3] Update regular_ball.cpp --- src/GameBall/logic/units/regular_ball.cpp | 74 +++++++++++------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index af1cc95..84de3e2 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -45,43 +45,43 @@ void RegularBall::UpdateTick() { auto physics_world = world_->PhysicsWorld(); auto &sphere = physics_world->GetSphere(sphere_id_); - // auto owner = world_->GetPlayer(player_id_); - // if (owner) { - // if (UnitId() == owner->PrimaryUnitId()) { - // auto input = owner->TakePlayerInput(); - // - // glm::vec3 forward = glm::normalize(glm::vec3{input.orientation}); - // glm::vec3 right = - // glm::normalize(glm::cross(forward, glm::vec3{0.0f, 1.0f, 0.0f})); - // - // glm::vec3 moving_direction{}; - // - // float angular_acceleration = glm::radians(2880.0f); - // - // if (input.move_forward) { - // moving_direction -= right; - // } - // if (input.move_backward) { - // moving_direction += right; - // } - // if (input.move_left) { - // moving_direction -= forward; - // } - // if (input.move_right) { - // moving_direction += forward; - // } - // - // if (glm::length(moving_direction) > 0.0f) { - // moving_direction = glm::normalize(moving_direction); - // sphere.angular_velocity += - // moving_direction * angular_acceleration * delta_time; - // } - // - // if (input.brake) { - // sphere.angular_velocity = glm::vec3{0.0f}; - // } - // } - // } + auto owner = world_->GetPlayer(player_id_); + if (owner) { + if (UnitId() == owner->PrimaryUnitId()) { + auto input = owner->TakePlayerInput(); + + glm::vec3 forward = glm::normalize(glm::vec3{input.orientation}); + glm::vec3 right = + glm::normalize(glm::cross(forward, glm::vec3{0.0f, 1.0f, 0.0f})); + + glm::vec3 moving_direction{}; + + float angular_acceleration = glm::radians(2880.0f); + + if (input.move_forward) { + moving_direction += forward; + } + if (input.move_backward) { + moving_direction -= forward; + } + if (input.move_left) { + moving_direction -= right; + } + if (input.move_right) { + moving_direction += right; + } + + if (glm::length(moving_direction) > 0.0f) { + moving_direction = glm::normalize(moving_direction); + sphere.angular_velocity += + moving_direction * angular_acceleration * delta_time; + } + + if (input.brake) { + sphere.angular_velocity = glm::vec3{0.0f}; + } + } + } sphere.velocity *= std::pow(0.5f, delta_time); sphere.angular_velocity *= std::pow(0.2f, delta_time); From 28fa1e68d2a878392271810200a1010b794fc37e Mon Sep 17 00:00:00 2001 From: muyanzhou <139620692+muyanzhou@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:25:10 +0800 Subject: [PATCH 2/3] Update regular_ball.cpp --- src/GameBall/logic/units/regular_ball.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index 84de3e2..1e1bb31 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -59,16 +59,16 @@ void RegularBall::UpdateTick() { float angular_acceleration = glm::radians(2880.0f); if (input.move_forward) { - moving_direction += forward; + moving_direction -= right; } if (input.move_backward) { - moving_direction -= forward; + moving_direction += right; } if (input.move_left) { - moving_direction -= right; + moving_direction -= forward; } if (input.move_right) { - moving_direction += right; + moving_direction += forward; } if (glm::length(moving_direction) > 0.0f) { From 948e477c36d901e5cf7b1fe27b8753f513fa43ca Mon Sep 17 00:00:00 2001 From: muyanzhou <139620692+muyanzhou@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:37:47 +0800 Subject: [PATCH 3/3] [Feat] Enable input control --- src/GameBall/logic/units/regular_ball.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GameBall/logic/units/regular_ball.cpp b/src/GameBall/logic/units/regular_ball.cpp index 1e1bb31..ffb59cc 100644 --- a/src/GameBall/logic/units/regular_ball.cpp +++ b/src/GameBall/logic/units/regular_ball.cpp @@ -45,7 +45,7 @@ void RegularBall::UpdateTick() { auto physics_world = world_->PhysicsWorld(); auto &sphere = physics_world->GetSphere(sphere_id_); - auto owner = world_->GetPlayer(player_id_); + auto owner = world_->GetPlayer(player_id_);; if (owner) { if (UnitId() == owner->PrimaryUnitId()) { auto input = owner->TakePlayerInput();