At the moment the input direction in the demo is defined with this (in motion.gd):
func get_input_direction():
var input_direction = Vector2()
input_direction.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
input_direction.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
return input_direction
My usable version of movement detects the direction of the touch from player, like this:
func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
var local_event = make_input_local(event)
if local_event.position.x > 20:
state = STATES.MoveRight
elif local_event.position.x < -20:
state = STATES.MoveLeft
elif round(local_event.position.x) in range(-19, 19):
if is_on_ladder:
state = STATES.Climb
elif not is_on_ladder:
state = STATES.Jump
else:
state = STATES.Idle
The node structure of the demo is:
KinematicBody2d
State machine
Idle
Move
Jump
The script structure of the demo is:
player_controller.gd (extends KinematicBody2d)
state_machine.gd (extends Node "StateMachine")
player_node_state_machine.gd (extends Node "StateMachine")
state.gd (extends Node "StateMachine")
motion.gd
on_ground.gd
idle
move.gd
on_air.gd
jump