Change 2D avoidance callbacks from Vector3 to Vector2

Changes 2D avoidance callbacks from Vector3 to Vector2.
This commit is contained in:
smix8 2025-06-07 13:42:51 +02:00
parent 42c7f14422
commit 0ce53ffc69
4 changed files with 16 additions and 17 deletions

View file

@ -111,9 +111,9 @@ void NavAgent2D::dispatch_avoidance_callback() {
return;
}
Vector3 new_velocity;
Vector2 new_velocity;
new_velocity = Vector3(rvo_agent.velocity_.x(), 0.0, rvo_agent.velocity_.y());
new_velocity = Vector2(rvo_agent.velocity_.x(), rvo_agent.velocity_.y());
if (clamp_speed) {
new_velocity = new_velocity.limit_length(max_speed);

View file

@ -652,9 +652,8 @@ void NavigationAgent2D::set_velocity(const Vector2 p_velocity) {
velocity_submitted = true;
}
void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) {
const Vector2 new_safe_velocity = Vector2(p_new_velocity.x, p_new_velocity.z);
safe_velocity = new_safe_velocity;
void NavigationAgent2D::_avoidance_done(Vector2 p_new_velocity) {
safe_velocity = p_new_velocity;
emit_signal(SNAME("velocity_computed"), safe_velocity);
}

View file

@ -203,7 +203,7 @@ public:
void set_velocity_forced(const Vector2 p_velocity);
void _avoidance_done(Vector3 p_new_velocity);
void _avoidance_done(Vector2 p_new_velocity);
PackedStringArray get_configuration_warnings() const override;

View file

@ -392,7 +392,7 @@ TEST_SUITE("[Navigation2D]") {
CHECK_EQ(agent_avoidance_callback_mock.function1_calls, 0);
navigation_server->physics_process(0.0); // Give server some cycles to commit.
CHECK_EQ(agent_avoidance_callback_mock.function1_calls, 1);
CHECK_NE(agent_avoidance_callback_mock.function1_latest_arg0, Vector3(0, 0, 0));
CHECK_NE(agent_avoidance_callback_mock.function1_latest_arg0, Vector2(0, 0));
navigation_server->free(agent);
navigation_server->free(map);
@ -429,12 +429,12 @@ TEST_SUITE("[Navigation2D]") {
navigation_server->physics_process(0.0); // Give server some cycles to commit.
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1);
CHECK_EQ(agent_2_avoidance_callback_mock.function1_calls, 1);
Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
Vector3 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
Vector2 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
Vector2 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "agent 1 should move a bit along desired velocity (+X)");
CHECK_MESSAGE(agent_2_safe_velocity.x < 0, "agent 2 should move a bit along desired velocity (-X)");
CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "agent 1 should move a bit to the side so that it avoids agent 2");
CHECK_MESSAGE(agent_2_safe_velocity.z > 0, "agent 2 should move a bit to the side so that it avoids agent 1");
CHECK_MESSAGE(agent_1_safe_velocity.y < 0, "agent 1 should move a bit to the side so that it avoids agent 2");
CHECK_MESSAGE(agent_2_safe_velocity.y > 0, "agent 2 should move a bit to the side so that it avoids agent 1");
navigation_server->free(agent_2);
navigation_server->free(agent_1);
@ -466,9 +466,9 @@ TEST_SUITE("[Navigation2D]") {
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 0);
navigation_server->physics_process(0.0); // Give server some cycles to commit.
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1);
Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
Vector2 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "Agent 1 should move a bit along desired velocity (+X).");
CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
CHECK_MESSAGE(agent_1_safe_velocity.y < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
navigation_server->free(obstacle_1);
navigation_server->free(agent_1);
@ -518,12 +518,12 @@ TEST_SUITE("[Navigation2D]") {
navigation_server->physics_process(0.0); // Give server some cycles to commit.
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1);
CHECK_EQ(agent_2_avoidance_callback_mock.function1_calls, 1);
Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
Vector3 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
Vector2 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
Vector2 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "Agent 1 should move a bit along desired velocity (+X).");
CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
CHECK_MESSAGE(agent_1_safe_velocity.y < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
CHECK_MESSAGE(agent_2_safe_velocity.x > 0, "Agent 2 should move a bit along desired velocity (+X).");
CHECK_MESSAGE(agent_2_safe_velocity.z == 0, "Agent 2 should not move to the side.");
CHECK_MESSAGE(agent_2_safe_velocity.y == 0, "Agent 2 should not move to the side.");
navigation_server->free(obstacle_1);
navigation_server->free(agent_2);