From 2899e4b521750defebb2eb9dc7107c341ab199d8 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Sat, 5 Feb 2022 01:59:43 +0100 Subject: [PATCH] adding animation sit if press 'x', simplify zoom code --- player/player.gd | 33 +++++++++++++++++++-------------- project.godot | 5 +++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/player/player.gd b/player/player.gd index d84c4fd..c7382e5 100644 --- a/player/player.gd +++ b/player/player.gd @@ -13,11 +13,10 @@ const SPEED_RUN_STRAFE = SPEED_WALK_STRAFE * 2.0 const SPEED_RUN_DOWN_STRAFE = SPEED_WALK_DOWN_STRAFE * 2.0 const SPEED_RUN_DOWN = SPEED_WALK_DOWN * 2.0 -const ZOOM_Y = 0.05 -const ZOOM_Z = 0.1 -const ZOOM_STEP = 0.1 -const ZOOM_MIN = 0.2 -const ZOOM_MAX = 3.0 +const ZOOM_STEP_Y = 0.05 +const ZOOM_STEP_Z = 0.1 +const ZOOM_MIN_Z = 0.2 +const ZOOM_MAX_Z = 3.0 const SPEED_ROTATE = PI const PI_2 = PI / 2.0 @@ -48,6 +47,7 @@ var anim_strafe_right_walk:String = "CHAR_strafe_right_walk" var anim_walk:String = "CHAR_walk" var anim_walk_backward:String = "CHAR_walk_backward" var current_anim:String = anim_idle +var player_sit:bool = false func search_animation( obj:Node , root:String = "/") -> bool: @@ -96,11 +96,11 @@ func _input(event): # Managed zoom (FPS or TPS) if Input.is_action_pressed("camera_zoom_in"): if tps: - if zoom > ZOOM_MIN: - zoom -= ZOOM_STEP - var zoom3D:Vector3 = Vector3(0.0, -ZOOM_Y, -ZOOM_Z) + if zoom > ZOOM_MIN_Z: + zoom -= ZOOM_STEP_Z + var zoom3D:Vector3 = Vector3(0.0, -ZOOM_STEP_Y, -ZOOM_STEP_Z) $camera_root/horizontal_root/vertical_root/Camera3D_TPS.translate_object_local(zoom3D) - if zoom < ZOOM_MIN: + if zoom < ZOOM_MIN_Z: $camera_root/Camera3D_FPS.make_current() tps = false reconciliate_rotate_camera_player = false @@ -114,13 +114,15 @@ func _input(event): # camera_rotate_y = player_rotate_y reconciliate_rotate_camera_player = true tps = true - zoom += ZOOM_STEP + zoom += ZOOM_STEP_Z $camera_root/horizontal_root/vertical_root/Camera3D_TPS.make_current() - if zoom >= ZOOM_MAX: - zoom = ZOOM_MAX + if zoom >= ZOOM_MAX_Z: + zoom = ZOOM_MAX_Z else: - var zoom3D:Vector3 = Vector3(0.0, ZOOM_Y, ZOOM_Z) + var zoom3D:Vector3 = Vector3(0.0, ZOOM_STEP_Y, ZOOM_STEP_Z) $camera_root/horizontal_root/vertical_root/Camera3D_TPS.translate_object_local(zoom3D) + elif Input.is_action_just_pressed("sit"): + player_sit = not player_sit # If right mouse button is pressed and mouse moves, pan horizontally camera # and rotate vertically @@ -270,7 +272,10 @@ func _physics_process(delta): else: switch_animation(anim_idle) if input_x == 0.0 and input_y == 0.0: - switch_animation(anim_idle) + if player_sit: + switch_animation(anim_sitting_ground_idle) + else: + switch_animation(anim_idle) var direction = (transform.basis * Vector3(input_x, 0, input_y)).normalized() if direction: diff --git a/project.godot b/project.godot index c7ddd8f..781aee1 100644 --- a/project.godot +++ b/project.godot @@ -65,3 +65,8 @@ camera_zoom_out={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"pressed":false,"double_click":false,"script":null) ] } +sit={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":88,"physical_keycode":0,"unicode":120,"echo":false,"script":null) +] +}