└── addons └── wasd ├── InputController2D.gd ├── InputController2D.tscn ├── LICENSE ├── icon.svg ├── icon.svg.import ├── plugin.cfg └── plugin.gd /addons/wasd/InputController2D.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | class_name InputController2D extends Node 3 | @icon("icon.svg") 4 | 5 | @export var action_left := "ui_left" 6 | @export var action_right := "ui_right" 7 | @export var action_up := "ui_up" 8 | @export var action_down := "ui_down" 9 | @export var acceleration := 50.0 10 | @export var friction := 10.0 11 | @export var maximum_speed := 100.0 12 | 13 | var input_vector := Vector2.ZERO 14 | var velocity := Vector2.ZERO 15 | var look_direction := Vector2.ZERO 16 | var move_direction := Vector2.ZERO 17 | 18 | func get_look_direction() -> Vector2: 19 | return look_direction 20 | 21 | func get_move_direction() -> Vector2: 22 | return move_direction 23 | 24 | func _physics_process(delta: float) -> void: 25 | if Engine.is_editor_hint(): 26 | return 27 | 28 | input_vector.x = Input.get_action_strength(action_right) - Input.get_action_strength(action_left) 29 | input_vector.y = Input.get_action_strength(action_down) - Input.get_action_strength(action_up) 30 | 31 | if input_vector.length() != 0: 32 | look_direction = input_vector.normalized() 33 | 34 | velocity = velocity.move_toward(input_vector * maximum_speed * delta, _get_acceleration(input_vector) * delta) 35 | 36 | if get_parent() is CharacterBody2D: 37 | var parent = get_parent() as CharacterBody2D 38 | parent.velocity = velocity 39 | parent.move_and_slide() 40 | velocity = parent.velocity 41 | elif get_parent() is Node2D: 42 | var parent = get_parent() as Node2D 43 | parent.global_position += velocity 44 | 45 | if velocity.length() != 0: 46 | move_direction = velocity.normalized() 47 | 48 | func _get_acceleration(input_vector:Vector2) -> float: 49 | if input_vector == Vector2.ZERO: 50 | return friction 51 | else: 52 | return acceleration 53 | 54 | func _get_configuration_warnings() -> PackedStringArray: 55 | var warnings = [] 56 | if acceleration <= 0.0: 57 | warnings.append("'acceleration' must be greater than 0.") 58 | if maximum_speed <= 0.0: 59 | warnings.append("'maximum_speed' must be greater than 0.") 60 | if action_left.is_empty(): 61 | warnings.append("'action_left' is not specified.") 62 | if action_right.is_empty(): 63 | warnings.append("'action_right' is not specified.") 64 | if action_up.is_empty(): 65 | warnings.append("'action_up' is not specified.") 66 | if action_down.is_empty(): 67 | warnings.append("'action_down' is not specified.") 68 | if not get_parent() is Node2D: 69 | warnings.append("Must be child of Node2D or CharacterBody2D") 70 | return PackedStringArray(warnings) 71 | -------------------------------------------------------------------------------- /addons/wasd/InputController2D.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=2 format=3 uid="uid://dq2avc11mm5s0"] 2 | 3 | [ext_resource type="Script" path="res://addons/wasd/InputController2D.gd" id="1_xto1a"] 4 | 5 | [node name="InputController2D" type="Node"] 6 | script = ExtResource("1_xto1a") 7 | -------------------------------------------------------------------------------- /addons/wasd/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 miguel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /addons/wasd/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 34 | 39 | 40 | -------------------------------------------------------------------------------- /addons/wasd/icon.svg.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="CompressedTexture2D" 5 | uid="uid://bjgnc1m6e4wpg" 6 | path="res://.godot/imported/icon.svg-da4a283f945d1635bc366a2b9f003c40.ctex" 7 | metadata={ 8 | "vram_texture": false 9 | } 10 | 11 | [deps] 12 | 13 | source_file="res://addons/wasd/icon.svg" 14 | dest_files=["res://.godot/imported/icon.svg-da4a283f945d1635bc366a2b9f003c40.ctex"] 15 | 16 | [params] 17 | 18 | compress/mode=0 19 | compress/lossy_quality=0.7 20 | compress/hdr_compression=1 21 | compress/bptc_ldr=0 22 | compress/normal_map=0 23 | compress/channel_pack=0 24 | mipmaps/generate=false 25 | mipmaps/limit=-1 26 | roughness/mode=0 27 | roughness/src_normal="" 28 | process/fix_alpha_border=true 29 | process/premult_alpha=false 30 | process/normal_map_invert_y=false 31 | process/hdr_as_srgb=false 32 | process/hdr_clamp_exposure=false 33 | process/size_limit=0 34 | detect_3d/compress_to=1 35 | svg/scale=1.0 36 | editor/scale_with_editor_scale=false 37 | editor/convert_colors_with_editor_theme=false 38 | -------------------------------------------------------------------------------- /addons/wasd/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="WASD" 4 | description="🎮 Simple 2D Input Controller" 5 | author="bitbrain" 6 | version="1.0.0" 7 | script="plugin.gd" 8 | -------------------------------------------------------------------------------- /addons/wasd/plugin.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends EditorPlugin 3 | 4 | func _init(): 5 | print("WASD initialised.") 6 | --------------------------------------------------------------------------------