Browse Source

Change 2D avoidance callbacks from Vector3 to Vector2

Changes 2D avoidance callbacks from Vector3 to Vector2.
smix8 2 months ago
parent
commit
0ce53ffc69

+ 2 - 2
modules/navigation_2d/nav_agent_2d.cpp

@@ -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);

+ 2 - 3
scene/2d/navigation/navigation_agent_2d.cpp

@@ -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);
 }
 

+ 1 - 1
scene/2d/navigation/navigation_agent_2d.h

@@ -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;
 

+ 11 - 11
tests/servers/test_navigation_server_2d.h

@@ -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);