diff --git a/player/player.gd b/player/player.gd index e7fd765..79d1fae 100644 --- a/player/player.gd +++ b/player/player.gd @@ -14,6 +14,7 @@ var max_angle = PI / 2 const TWO_PI = 2.0 * PI const PI_2 = PI / 2.0 var debug:bool = false +var reconciliate_rotate_camer_player:bool = true func _init(): @@ -29,8 +30,10 @@ func _input(event): # If right mouse button is pressed and mouse moves, pan horizontally camera # and rotate vertically if Input.is_action_just_pressed ( "ui_strafe" ): + reconciliate_rotate_camer_player = false Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) elif Input.is_action_just_released ( "ui_strafe" ): + reconciliate_rotate_camer_player = true Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) if Input.is_action_just_released("ui_cut"): print("debug on") @@ -96,31 +99,33 @@ func _physics_process(delta): func _process( delta ): if debug: - print(camera_rotate_y,", ", player_rotate_y) - var diff = camera_rotate_y - player_rotate_y + print(reconciliate_rotate_camer_player, ", ", camera_rotate_y,", ", player_rotate_y) - if diff > PI: - diff = camera_rotate_y - player_rotate_y - TWO_PI - elif diff < -PI: - diff = camera_rotate_y - player_rotate_y + TWO_PI + if reconciliate_rotate_camer_player: + var diff = camera_rotate_y - player_rotate_y - var absdiff = diff - if absdiff < 0.0: - absdiff = -absdiff + if diff > PI: + diff = camera_rotate_y - player_rotate_y - TWO_PI + elif diff < -PI: + diff = camera_rotate_y - player_rotate_y + TWO_PI - if absdiff <= 0.5 * delta: - rotate_y( diff ) - $camera_root/horizontal_root.rotate_y( -diff ) - player_rotate_y = camera_rotate_y - else: - if diff >= 0.0: - diff = delta * speed_rotate_1sec + var absdiff = diff + if absdiff < 0.0: + absdiff = -absdiff + + if absdiff <= 0.5 * delta: + rotate_y( diff ) + $camera_root/horizontal_root.rotate_y( -diff ) + player_rotate_y = camera_rotate_y else: - diff = -delta * speed_rotate_1sec - rotate_y( diff ) - $camera_root/horizontal_root.rotate_y( -diff ) - player_rotate_y += diff - if player_rotate_y > PI: - player_rotate_y -= TWO_PI - elif player_rotate_y <= -PI: - player_rotate_y += TWO_PI + if diff >= 0.0: + diff = delta * speed_rotate_1sec + else: + diff = -delta * speed_rotate_1sec + rotate_y( diff ) + $camera_root/horizontal_root.rotate_y( -diff ) + player_rotate_y += diff + if player_rotate_y > PI: + player_rotate_y -= TWO_PI + elif player_rotate_y <= -PI: + player_rotate_y += TWO_PI