update camera usage on fps

This commit is contained in:
AleaJactaEst 2022-02-06 23:41:32 +01:00
parent 4a05c059fd
commit 804a11d1ca

View file

@ -93,24 +93,40 @@ func switch_state(new_state):
#$carpet.hide() #$carpet.hide()
camera_fps.rotate_x( -player_rotate_x ) camera_fps.rotate_x( -player_rotate_x )
player_rotate_x = 0 player_rotate_x = 0
if get_viewport().get_camera_3d() == camera_fps:
camera_fps = $camera_root/Camera3D_FPS_WALK
camera_fps.make_current()
else:
camera_fps = $camera_root/Camera3D_FPS_WALK camera_fps = $camera_root/Camera3D_FPS_WALK
StatePlayer.WALK: StatePlayer.WALK:
print("switch camera WALK") print("switch camera WALK")
#$carpet.hide() #$carpet.hide()
camera_fps.rotate_x( -player_rotate_x ) camera_fps.rotate_x( -player_rotate_x )
player_rotate_x = 0 player_rotate_x = 0
if get_viewport().get_camera_3d() == camera_fps:
camera_fps = $camera_root/Camera3D_FPS_WALK
camera_fps.make_current()
else:
camera_fps = $camera_root/Camera3D_FPS_WALK camera_fps = $camera_root/Camera3D_FPS_WALK
StatePlayer.FLY: StatePlayer.FLY:
print("switch camera FLY") print("switch camera FLY")
#$carpet.show() #$carpet.show()
camera_fps.rotate_x( -player_rotate_x ) camera_fps.rotate_x( -player_rotate_x )
player_rotate_x = 0 player_rotate_x = 0
if get_viewport().get_camera_3d() == camera_fps:
camera_fps = $camera_root/Camera3D_FPS_FLY
camera_fps.make_current()
else:
camera_fps = $camera_root/Camera3D_FPS_FLY camera_fps = $camera_root/Camera3D_FPS_FLY
StatePlayer.SWIM: StatePlayer.SWIM:
print("switch camera SWIM") print("switch camera SWIM")
#$carpet.hide() #$carpet.hide()
camera_fps.rotate_x( -player_rotate_x ) camera_fps.rotate_x( -player_rotate_x )
player_rotate_x = 0 player_rotate_x = 0
if get_viewport().get_camera_3d() == camera_fps:
camera_fps = $camera_root/Camera3D_FPS_SWIM
camera_fps.make_current()
else:
camera_fps = $camera_root/Camera3D_FPS_SWIM camera_fps = $camera_root/Camera3D_FPS_SWIM
@ -198,12 +214,8 @@ func _input(event):
elif Input.is_action_just_pressed("switch_state_player"): elif Input.is_action_just_pressed("switch_state_player"):
match state_player: match state_player:
StatePlayer.WALK: StatePlayer.WALK:
print("FLY")
#state_player = StatePlayer.FLY
switch_state(StatePlayer.FLY) switch_state(StatePlayer.FLY)
StatePlayer.FLY: StatePlayer.FLY:
print("SWIM")
#state_player = StatePlayer.WALK
switch_state(StatePlayer.WALK) switch_state(StatePlayer.WALK)
# If right mouse button is pressed and mouse moves, pan horizontally camera # If right mouse button is pressed and mouse moves, pan horizontally camera
@ -235,14 +247,14 @@ func _input(event):
$camera_root/horizontal_root/vertical_root.rotate_x( event.relative.y * 0.01 ) $camera_root/horizontal_root/vertical_root.rotate_x( event.relative.y * 0.01 )
camera_rotate_x = new_camera_rotate_x camera_rotate_x = new_camera_rotate_x
else: else:
player_rotate_y += event.relative.x *0.01
if player_rotate_y > PI: if player_rotate_y > PI:
player_rotate_y -= TAU player_rotate_y -= TAU
elif player_rotate_y <= -PI: elif player_rotate_y <= -PI:
player_rotate_y += TAU player_rotate_y += TAU
camera_rotate_y = player_rotate_y camera_rotate_y = player_rotate_y
rotate_y( -event.relative.x *0.01 )
player_rotate_y += event.relative.x *0.01
rotate_y( -event.relative.x *0.01 )
var new_camera_rotate_x = player_rotate_x + event.relative.y * 0.01 var new_camera_rotate_x = player_rotate_x + event.relative.y * 0.01
if new_camera_rotate_x <= PI_2 and new_camera_rotate_x >= - PI_2: if new_camera_rotate_x <= PI_2 and new_camera_rotate_x >= - PI_2:
camera_fps.rotate_x( event.relative.y * 0.01 ) camera_fps.rotate_x( event.relative.y * 0.01 )