From 2235ce182f11b3d2fb898bb31961184642f52caf Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Mon, 17 Feb 2020 04:48:55 -0500 Subject: [PATCH] Tweak controller support --- level/level.gd | 6 +++--- menu/menu.gd | 24 ++++++++++++------------ player/player.gd | 15 +++++++++++---- project.godot | 16 ++++++++++++---- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/level/level.gd b/level/level.gd index 8d0727e..8e99231 100644 --- a/level/level.gd +++ b/level/level.gd @@ -35,13 +35,13 @@ func _ready(): pass elif settings.resolution == settings.Resolution.RES_1080: var minsize = Vector2(OS.window_size.x * 1080 / OS.window_size.y, 1080.0) - get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_KEEP_HEIGHT,minsize) + get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT, SceneTree.STRETCH_ASPECT_KEEP_HEIGHT, minsize) elif settings.resolution == settings.Resolution.RES_720: var minsize = Vector2(OS.window_size.x * 720 / OS.window_size.y, 720.0) - get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_KEEP_HEIGHT,minsize) + get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT, SceneTree.STRETCH_ASPECT_KEEP_HEIGHT, minsize) elif settings.resolution == settings.Resolution.RES_576: var minsize = Vector2(OS.window_size.x * 576 / OS.window_size.y, 576.0) - get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_KEEP_HEIGHT,minsize) + get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT, SceneTree.STRETCH_ASPECT_KEEP_HEIGHT, minsize) func _input(event): diff --git a/menu/menu.gd b/menu/menu.gd index fd3a5f9..b961d86 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -58,27 +58,27 @@ func _on_settings_pressed(): $ui/settings/actions/cancel.grab_focus() if settings.gi_quality == settings.GIQuality.HIGH: - $ui/settings/gi/gi_high.pressed=true + $ui/settings/gi/gi_high.pressed = true elif settings.gi_quality == settings.GIQuality.LOW: - $ui/settings/gi/gi_low.pressed=true + $ui/settings/gi/gi_low.pressed = true elif settings.gi_quality == settings.GIQuality.DISABLED: - $ui/settings/gi/gi_disabled.pressed=true + $ui/settings/gi/gi_disabled.pressed = true if settings.aa_quality == settings.AAQuality.AA_8X: - $ui/settings/aa/aa_8x.pressed=true + $ui/settings/aa/aa_8x.pressed = true elif settings.aa_quality == settings.AAQuality.AA_4X: - $ui/settings/aa/aa_4x.pressed=true + $ui/settings/aa/aa_4x.pressed = true elif settings.aa_quality == settings.AAQuality.AA_2X: - $ui/settings/aa/aa_2x.pressed=true - elif settings.aa_quality == settings.AAQuality.AA_DISABLED: - $ui/settings/aa/aa_disabled.pressed=true + $ui/settings/aa/aa_2x.pressed = true + elif settings.aa_quality == settings.AAQuality.DISABLED: + $ui/settings/aa/aa_disabled.pressed = true if settings.ssao_quality == settings.SSAOQuality.HIGH: - $ui/settings/ssao/ssao_high.pressed=true + $ui/settings/ssao/ssao_high.pressed = true elif settings.ssao_quality == settings.SSAOQuality.LOW: - $ui/settings/ssao/ssao_low.pressed=true + $ui/settings/ssao/ssao_low.pressed = true elif settings.ssao_quality == settings.SSAOQuality.DISABLED: - $ui/settings/ssao/ssao_disabled.pressed=true + $ui/settings/ssao/ssao_disabled.pressed = true if settings.resolution == settings.Resolution.NATIVE: $ui/settings/resolution/resolution_native.pressed = true @@ -118,7 +118,7 @@ func _on_apply_pressed(): elif $ui/settings/aa/aa_2x.pressed: settings.aa_quality = settings.AAQuality.AA_2X elif $ui/settings/aa/aa_disabled.pressed: - settings.aa_quality = settings.AAQuality.AA_DISABLED + settings.aa_quality = settings.AAQuality.DISABLED if $ui/settings/ssao/ssao_high.pressed: settings.ssao_quality = settings.SSAOQuality.HIGH diff --git a/player/player.gd b/player/player.gd index 0c0d40b..cc1b957 100644 --- a/player/player.gd +++ b/player/player.gd @@ -1,7 +1,7 @@ extends KinematicBody const CAMERA_MOUSE_ROTATION_SPEED = 0.001 -const CAMERA_CONTROLLER_ROTATION_SPEED = 1.0 +const CAMERA_CONTROLLER_ROTATION_SPEED = 3.0 const CAMERA_X_ROT_MIN = -40 const CAMERA_X_ROT_MAX = 30 @@ -33,6 +33,7 @@ func _ready(): orientation = $"Scene Root".global_transform orientation.origin = Vector3() + func rotate_camera(move): $camera_base.rotate_y(-move.x) $camera_base.orthonormalize() # After relative transforms, camera needs to be renormalized. @@ -40,10 +41,14 @@ func rotate_camera(move): camera_x_rot = clamp(camera_x_rot, deg2rad(CAMERA_X_ROT_MIN), deg2rad(CAMERA_X_ROT_MAX)) $camera_base/camera_rot.rotation.x = camera_x_rot + func _physics_process(delta): var camera_move = Vector2(Input.get_action_strength("view_right") - Input.get_action_strength("view_left"), Input.get_action_strength("view_up") - Input.get_action_strength("view_down")) - rotate_camera(camera_move * delta * CAMERA_CONTROLLER_ROTATION_SPEED) + var camera_speed_this_frame = delta * CAMERA_CONTROLLER_ROTATION_SPEED + if aiming: + camera_speed_this_frame *= 0.5 + rotate_camera(camera_move * camera_speed_this_frame) var motion_target = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), Input.get_action_strength("move_forward") - Input.get_action_strength("move_back")) motion = motion.linear_interpolate(motion_target, MOTION_INTERPOLATE_SPEED * delta) @@ -102,7 +107,6 @@ func _physics_process(delta): # Interpolate current rotation with desired one. orientation.basis = Basis(q_from.slerp(q_to, delta * ROTATION_INTERPOLATE_SPEED)) - $animation_tree["parameters/strafe/blend_position"] = motion root_motion = $animation_tree.get_root_motion_transform() @@ -165,4 +169,7 @@ func _physics_process(delta): func _input(event): if event is InputEventMouseMotion: - rotate_camera(event.relative * CAMERA_MOUSE_ROTATION_SPEED) + var camera_speed_this_frame = CAMERA_MOUSE_ROTATION_SPEED + if aiming: + camera_speed_this_frame *= 0.75 + rotate_camera(event.relative * camera_speed_this_frame) diff --git a/project.godot b/project.godot index 199330c..2cfd29f 100644 --- a/project.godot +++ b/project.godot @@ -115,24 +115,32 @@ move_left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) ] } move_right={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) ] } move_forward={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) ] } move_back={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) ] } jump={ @@ -160,22 +168,22 @@ quit={ ] } view_left={ -"deadzone": 0.5, +"deadzone": 0.2, "events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":2,"axis_value":-1.0,"script":null) ] } view_right={ -"deadzone": 0.5, +"deadzone": 0.2, "events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":2,"axis_value":1.0,"script":null) ] } view_up={ -"deadzone": 0.5, +"deadzone": 0.2, "events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":3,"axis_value":1.0,"script":null) ] } view_down={ -"deadzone": 0.5, +"deadzone": 0.2, "events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":3,"axis_value":-1.0,"script":null) ] }