@@ -102,25 +102,28 @@ def _wasd_movement(self, entity_id, speed, vertical_movement, vertical_speed):
102102 print (f"Transformation(Position: { tra .position } , Rotation: { tra .rotation } )" )
103103
104104 def _mouse_control (self , entity_id , enable_pitch = True ):
105+ controls : res .GameControlState = self .world .controls
106+ screen_center = self .world .resolution / 2.0
107+
108+ # If python breaks on this try updating pygame :D
105109 (is_pressed , _ , _ , _ , _ ) = pygame .mouse .get_pressed ()
106- transformation = self .world .component_for_entity (entity_id , com .Transformation )
107- (rel_x , rel_y ) = pygame .mouse .get_rel ()
108110 if is_pressed :
111+ transformation = self .world .component_for_entity (entity_id , com .Transformation )
112+ #(rel_x, rel_y) = pygame.mouse.get_rel()
113+ (pos_x , pos_y ) = pygame .mouse .get_pos ()
114+ rel_x = screen_center .x - pos_x
115+ rel_y = screen_center .y - pos_y
116+
109117 if enable_pitch :
110- pitch_change = 0.0
111- if rel_y > 0 :
112- pitch_change += 0.01 # I think it is too fast with change 0.1
113- if rel_y < 0 :
114- pitch_change -= 0.01
118+ pitch_change = rel_y * controls .mouse_sensitivity
115119 transformation .rotation .y = clamp (
116120 transformation .rotation .y + pitch_change ,
117121 (math .pi - 0.2 ) / - 2 ,
118122 (math .pi - 0.2 ) / 2 )
119123
120- if rel_x < 0 :
121- transformation .rotation .x += 0.1
122- if rel_x > 0 :
123- transformation .rotation .x -= 0.1
124+ transformation .rotation .x += rel_x * controls .mouse_sensitivity
125+
126+ pygame .mouse .set_pos ([screen_center .x , screen_center .y ])
124127
125128 def _arrow_key_rotation (self , entity_id , enable_pitch = True ):
126129 transformation = self .world .component_for_entity (entity_id , com .Transformation )
0 commit comments