From 750719ff889c9b05ed3181a7abf8fed51cfd0840 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 4 Jan 2025 23:36:17 -0600 Subject: [PATCH] Fixed input from controller --- project.godot | 5 +++++ scenes/TestScene.tscn | 2 +- scripts/RosaController.gd | 27 +++++++++++++-------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/project.godot b/project.godot index 74baefe..6097704 100644 --- a/project.godot +++ b/project.godot @@ -26,6 +26,7 @@ left={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null) ] } right={ @@ -33,6 +34,7 @@ right={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null) ] } up={ @@ -40,6 +42,7 @@ up={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":false,"script":null) ] } down={ @@ -47,12 +50,14 @@ down={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":false,"script":null) ] } interact={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) ] } diff --git a/scenes/TestScene.tscn b/scenes/TestScene.tscn index 0538dde..a0c80c0 100644 --- a/scenes/TestScene.tscn +++ b/scenes/TestScene.tscn @@ -26,7 +26,7 @@ environment = SubResource("Environment_18twt") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.651853, 0.684572, -0.0593004) [node name="TestNpc" parent="." instance=ExtResource("2_6f3lj")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.545907, 0.459578, -0.399262) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.68747, 0.459578, -0.399262) [node name="OmniLight3D" type="OmniLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -38.1432, 54.7591, -25.7675) diff --git a/scripts/RosaController.gd b/scripts/RosaController.gd index b10ab3a..c0c59c2 100644 --- a/scripts/RosaController.gd +++ b/scripts/RosaController.gd @@ -27,22 +27,21 @@ func updateMovement(delta) -> void: if(dir.x != 0 or dir.y != 0): velocity.x = dir.x * speed * delta; velocity.z = dir.y * speed * delta; + print(dir.length()); # Update direction - if(dir.x > 0): - if( - dir.y == 0 or - (dir.y < 0 and direction == Direction.SOUTH) or - (dir.y > 0 and direction == Direction.NORTH) - ): - direction = Direction.EAST; - elif (dir.x < 0): - if( - dir.y == 0 or - (dir.y < 0 and direction == Direction.SOUTH) or - (dir.y > 0 and direction == Direction.NORTH) - ): - direction = Direction.WEST; + if(dir.x >= abs(dir.y) and( + dir.y == 0 or + (dir.y > 0 and direction != Direction.SOUTH) or + (dir.y < 0 and direction != Direction.NORTH) + )): + direction = Direction.EAST; + elif (dir.x <= -abs(dir.y) and ( + dir.y == 0 or + (dir.y > 0 and direction != Direction.SOUTH) or + (dir.y < 0 and direction != Direction.NORTH) + )): + direction = Direction.WEST; elif (dir.y > 0): direction = Direction.SOUTH; elif (dir.y < 0):