disable reconsiliate rotate between camera & player if left mousse is pressed

This commit is contained in:
AleaJactaEst 2022-02-03 14:02:38 +01:00
parent 824455501b
commit de250310af

View file

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