fix: player no longer rotates endlessly when hovered over
This commit is contained in:
		
							parent
							
								
									491e375b6e
								
							
						
					
					
						commit
						31b5312cf5
					
				|  | @ -65,8 +65,12 @@ void CharacterActor::move(Vector3 world_vector) { | ||||||
| 
 | 
 | ||||||
| void CharacterActor::aim(Vector3 at) { | void CharacterActor::aim(Vector3 at) { | ||||||
|     // calculate the forward vector by normalized difference between player character and the target on the XZ plane
 |     // calculate the forward vector by normalized difference between player character and the target on the XZ plane
 | ||||||
|     Vector3 const position{this->weapon_muzzle->get_global_position()}; |     Vector3 const pos_flat{this->get_global_position().x, 0.f, this->get_global_position().z}; | ||||||
|     Vector3 const forward{Vector3{at.x, 0.f, at.z} - Vector3{position.x, 0.f, position.z}}; |     Vector3 const target_flat{at.x, 0.f, at.z}; | ||||||
|  |     Vector3 const muzzle_flat{this->weapon_muzzle->get_global_position().x, 0.f, this->weapon_muzzle->get_global_position().z}; | ||||||
|  |     if(pos_flat.distance_squared_to(target_flat) < pos_flat.distance_squared_to(muzzle_flat)) | ||||||
|  |         return; | ||||||
|  |     Vector3 const forward{target_flat - muzzle_flat}; | ||||||
|     this->aim_direction(forward.normalized()); |     this->aim_direction(forward.normalized()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Sara
						Sara