Skip to content

Commit 151db00

Browse files
committed
Merge pull request #107256 from smix8/avoidance2dcallback
Change `NavigationServer2D` avoidance callbacks from `Vector3` to `Vector2`
2 parents 1eee38b + 0ce53ff commit 151db00

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

modules/navigation_2d/nav_agent_2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ void NavAgent2D::dispatch_avoidance_callback() {
111111
return;
112112
}
113113

114-
Vector3 new_velocity;
114+
Vector2 new_velocity;
115115

116-
new_velocity = Vector3(rvo_agent.velocity_.x(), 0.0, rvo_agent.velocity_.y());
116+
new_velocity = Vector2(rvo_agent.velocity_.x(), rvo_agent.velocity_.y());
117117

118118
if (clamp_speed) {
119119
new_velocity = new_velocity.limit_length(max_speed);

scene/2d/navigation/navigation_agent_2d.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,8 @@ void NavigationAgent2D::set_velocity(const Vector2 p_velocity) {
652652
velocity_submitted = true;
653653
}
654654

655-
void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) {
656-
const Vector2 new_safe_velocity = Vector2(p_new_velocity.x, p_new_velocity.z);
657-
safe_velocity = new_safe_velocity;
655+
void NavigationAgent2D::_avoidance_done(Vector2 p_new_velocity) {
656+
safe_velocity = p_new_velocity;
658657
emit_signal(SNAME("velocity_computed"), safe_velocity);
659658
}
660659

scene/2d/navigation/navigation_agent_2d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class NavigationAgent2D : public Node {
204204

205205
void set_velocity_forced(const Vector2 p_velocity);
206206

207-
void _avoidance_done(Vector3 p_new_velocity);
207+
void _avoidance_done(Vector2 p_new_velocity);
208208

209209
PackedStringArray get_configuration_warnings() const override;
210210

tests/servers/test_navigation_server_2d.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ TEST_SUITE("[Navigation2D]") {
392392
CHECK_EQ(agent_avoidance_callback_mock.function1_calls, 0);
393393
navigation_server->physics_process(0.0); // Give server some cycles to commit.
394394
CHECK_EQ(agent_avoidance_callback_mock.function1_calls, 1);
395-
CHECK_NE(agent_avoidance_callback_mock.function1_latest_arg0, Vector3(0, 0, 0));
395+
CHECK_NE(agent_avoidance_callback_mock.function1_latest_arg0, Vector2(0, 0));
396396

397397
navigation_server->free(agent);
398398
navigation_server->free(map);
@@ -429,12 +429,12 @@ TEST_SUITE("[Navigation2D]") {
429429
navigation_server->physics_process(0.0); // Give server some cycles to commit.
430430
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1);
431431
CHECK_EQ(agent_2_avoidance_callback_mock.function1_calls, 1);
432-
Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
433-
Vector3 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
432+
Vector2 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
433+
Vector2 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
434434
CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "agent 1 should move a bit along desired velocity (+X)");
435435
CHECK_MESSAGE(agent_2_safe_velocity.x < 0, "agent 2 should move a bit along desired velocity (-X)");
436-
CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "agent 1 should move a bit to the side so that it avoids agent 2");
437-
CHECK_MESSAGE(agent_2_safe_velocity.z > 0, "agent 2 should move a bit to the side so that it avoids agent 1");
436+
CHECK_MESSAGE(agent_1_safe_velocity.y < 0, "agent 1 should move a bit to the side so that it avoids agent 2");
437+
CHECK_MESSAGE(agent_2_safe_velocity.y > 0, "agent 2 should move a bit to the side so that it avoids agent 1");
438438

439439
navigation_server->free(agent_2);
440440
navigation_server->free(agent_1);
@@ -466,9 +466,9 @@ TEST_SUITE("[Navigation2D]") {
466466
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 0);
467467
navigation_server->physics_process(0.0); // Give server some cycles to commit.
468468
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1);
469-
Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
469+
Vector2 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
470470
CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "Agent 1 should move a bit along desired velocity (+X).");
471-
CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
471+
CHECK_MESSAGE(agent_1_safe_velocity.y < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
472472

473473
navigation_server->free(obstacle_1);
474474
navigation_server->free(agent_1);
@@ -518,12 +518,12 @@ TEST_SUITE("[Navigation2D]") {
518518
navigation_server->physics_process(0.0); // Give server some cycles to commit.
519519
CHECK_EQ(agent_1_avoidance_callback_mock.function1_calls, 1);
520520
CHECK_EQ(agent_2_avoidance_callback_mock.function1_calls, 1);
521-
Vector3 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
522-
Vector3 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
521+
Vector2 agent_1_safe_velocity = agent_1_avoidance_callback_mock.function1_latest_arg0;
522+
Vector2 agent_2_safe_velocity = agent_2_avoidance_callback_mock.function1_latest_arg0;
523523
CHECK_MESSAGE(agent_1_safe_velocity.x > 0, "Agent 1 should move a bit along desired velocity (+X).");
524-
CHECK_MESSAGE(agent_1_safe_velocity.z < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
524+
CHECK_MESSAGE(agent_1_safe_velocity.y < 0, "Agent 1 should move a bit to the side so that it avoids obstacle.");
525525
CHECK_MESSAGE(agent_2_safe_velocity.x > 0, "Agent 2 should move a bit along desired velocity (+X).");
526-
CHECK_MESSAGE(agent_2_safe_velocity.z == 0, "Agent 2 should not move to the side.");
526+
CHECK_MESSAGE(agent_2_safe_velocity.y == 0, "Agent 2 should not move to the side.");
527527

528528
navigation_server->free(obstacle_1);
529529
navigation_server->free(agent_2);

0 commit comments

Comments
 (0)