xyz So this code should rotate the visual node, right? It seems that its almost what i had already, only you check if input dir, while i check if direction.. why i use direction is because sometimes character might be in air or have inertia.. ill try your solution and report back. Thanks.
Also:
xyz Remove the prefix "action" from action names. Action names are always used in context, so why state the obvious and make your code needlessly verbose and repetitive.
I have it renamed because i have custom keybinds that are bound in code. Leaving the default names would conflict with the default project settings, which i dont want to touch, because those are defined usually through UI and after months of work i tend to forget where i have bound what button. Having a script that autoloads and rebinds "My actions" to the keys i have defined is much more reliable way to not get bugs later ..
Maybe the defaults are named differently, but thats besides the point, naming dont matter atm.
Here is my autoload
input_actions.gd
extends Node
var key_controls = {
"action_move_right": [KEY_RIGHT, KEY_D],
"action_move_left": [KEY_LEFT, KEY_A],
"action_move_forward": [KEY_UP, KEY_W],
"action_move_backward": [KEY_DOWN, KEY_S],
"action_jump": [KEY_SPACE],
"action_crouch": [KEY_CTRL],
"menu_main": [KEY_ESCAPE],
"tab_out": [KEY_TAB],
"action_sprint": [KEY_SHIFT],
"action_pickup": [KEY_E],
"action_enemy_follow": [KEY_F],
"action_savegame": [KEY_R],
"action_loadgame": [KEY_T],
}
var mouse_controls = {
"action_mouse_left": [MOUSE_BUTTON_LEFT],
"action_mouse_right": [MOUSE_BUTTON_RIGHT],
"action_mouse_middle": [MOUSE_BUTTON_MIDDLE],
"action_mouse_w_up": [MOUSE_BUTTON_WHEEL_UP],
"action_mouse_w_down": [MOUSE_BUTTON_WHEEL_DOWN],
}
func _ready():
add_key_inputs()
add_mouse_inputs()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
func _unhandled_input(_event):
if Input.is_action_pressed("menu_main"):
# Quits the game
get_tree().quit()
if Input.is_action_pressed("tab_out"):
# Quits the game
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
else:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
pass
func create_key_action(action_name:String,keycode:int):
InputMap.add_action(action_name)
var k = InputEventKey.new()
k.keycode = keycode
InputMap.action_add_event(action_name,k)
pass
func add_key_inputs():
var ev
for action in key_controls:
if not InputMap.has_action(action):
InputMap.add_action(action)
for key in key_controls[action]:
ev = InputEventKey.new()
ev.keycode = key
InputMap.action_add_event(action, ev)
func add_mouse_inputs():
var ev
for action in mouse_controls:
if not InputMap.has_action(action):
InputMap.add_action(action)
for key in mouse_controls[action]:
ev = InputEventMouseButton.new()
ev.button_index = key
InputMap.action_add_event(action, ev)