2D Movement Notes in Godot 3.2

  • Kinematic bodies can use move_and_slide() or move_and_collide() with a velocity vector
  • You can manually move by setting position and delta for non physics entities:
func _process(delta):
    # assuming velocity is a Vector2
    translate(velocity * delta)

Controls

Generally set up via using Godot’s built-in input mapping, and then retrieving joystick values:

func get_input():
    var left_joy_axis_h = Input.get_action_strength("l_right") - Input.get_action_strength("l_left")
    var left_joy_axis_v = Input.get_action_strength("l_down") - Input.get_action_strength("l_up")
    
    velocity = Vector2(left_joy_axis_h, left_joy_axis_v)
    velocity = velocity.normalized() * speed
    pass

func _physics_process(delta):
    get_input()
    player.move_and_slide(velocity)

https://docs.godotengine.org/en/3.1/tutorials/2d/2d_movement.html https://gamedev.stackexchange.com/questions/160426/how-do-i-use-get-action-strength-in-godot