fix: WretchedPatrolState now works without a path
This commit is contained in:
		
							parent
							
								
									ec6fc76335
								
							
						
					
					
						commit
						d8aafba90e
					
				| 
						 | 
					@ -56,17 +56,21 @@ void WretchedPatrolState::enter_state() {
 | 
				
			||||||
	float const max_speed{ get_unit()->get_patrol_speed() };
 | 
						float const max_speed{ get_unit()->get_patrol_speed() };
 | 
				
			||||||
	get_target()->set_movement_speed(max_speed);
 | 
						get_target()->set_movement_speed(max_speed);
 | 
				
			||||||
	get_nav()->set_max_speed(max_speed);
 | 
						get_nav()->set_max_speed(max_speed);
 | 
				
			||||||
 | 
						if (this->path) {
 | 
				
			||||||
		Vector3 const nav_target{ this->path->get_closest_point(get_target()->get_global_position(), &this->path_point) };
 | 
							Vector3 const nav_target{ this->path->get_closest_point(get_target()->get_global_position(), &this->path_point) };
 | 
				
			||||||
		set_patrol_target(nav_target);
 | 
							set_patrol_target(nav_target);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WretchedPatrolState::process(double delta) {
 | 
					void WretchedPatrolState::process(double delta) {
 | 
				
			||||||
 | 
						if (this->path) {
 | 
				
			||||||
		if (get_nav()->is_navigation_finished()) {
 | 
							if (get_nav()->is_navigation_finished()) {
 | 
				
			||||||
			this->path_point += 1;
 | 
								this->path_point += 1;
 | 
				
			||||||
			set_patrol_target(this->path->point_at(this->path_point));
 | 
								set_patrol_target(this->path->point_at(this->path_point));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		Vector3 const direction{ get_target()->get_global_position().direction_to(get_nav()->get_next_path_position()) };
 | 
							Vector3 const direction{ get_target()->get_global_position().direction_to(get_nav()->get_next_path_position()) };
 | 
				
			||||||
		get_target()->set_movement_direction(Vector2{ direction.x, direction.z }.normalized());
 | 
							get_target()->set_movement_direction(Vector2{ direction.x, direction.z }.normalized());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
String WretchedPatrolState::get_next_state() const {
 | 
					String WretchedPatrolState::get_next_state() const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
					@ -18,7 +18,6 @@ unique_name_in_owner = true
 | 
				
			||||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
 | 
					[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
 | 
				
			||||||
unique_name_in_owner = true
 | 
					unique_name_in_owner = true
 | 
				
			||||||
path_desired_distance = 0.25
 | 
					path_desired_distance = 0.25
 | 
				
			||||||
debug_enabled = true
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="PlayerDetector" type="PlayerDetector" parent="."]
 | 
					[node name="PlayerDetector" type="PlayerDetector" parent="."]
 | 
				
			||||||
unique_name_in_owner = true
 | 
					unique_name_in_owner = true
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										17
									
								
								project/objects/units/unit_4_wretched.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								project/objects/units/unit_4_wretched.tscn
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,17 @@
 | 
				
			||||||
 | 
					[gd_scene load_steps=2 format=3 uid="uid://5hg5eirw7v8n"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ext_resource type="PackedScene" uid="uid://dqlqgk1veyos8" path="res://objects/enemies/enemy_wretched.tscn" id="1_l77gx"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="NpcUnit" type="NpcUnit"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="EnemyWretched" parent="." instance=ExtResource("1_l77gx")]
 | 
				
			||||||
 | 
					transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -0.9145346, 0.023195954, -0.63123465)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="EnemyWretched2" parent="." instance=ExtResource("1_l77gx")]
 | 
				
			||||||
 | 
					transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 1.0534863, 0.023196908, -0.6773462)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="EnemyWretched3" parent="." instance=ExtResource("1_l77gx")]
 | 
				
			||||||
 | 
					transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -0.5066114, 0.023196908, 0.93247986)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="EnemyWretched4" parent="." instance=ExtResource("1_l77gx")]
 | 
				
			||||||
 | 
					transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 1.3384295, 0.023197861, 0.74458694)
 | 
				
			||||||
		Loading…
	
		Reference in a new issue