Skip to content

Instantly share code, notes, and snippets.

@oronbz
Last active December 7, 2021 08:29
Show Gist options
  • Save oronbz/1a75946a76516aa1aead622e667ca311 to your computer and use it in GitHub Desktop.
Save oronbz/1a75946a76516aa1aead622e667ca311 to your computer and use it in GitHub Desktop.
Joypad support for 1-bit-godot Metroidvania by heartbeast
extends Node
enum AimDevice {MOUSE, JOYPAD}
var last_device = null
var last_joypad_vector = null
func get_aim_vector(player):
if last_device in [AimDevice.MOUSE, null]:
return player.get_local_mouse_position()
if last_device == AimDevice.JOYPAD:
return Vector2(last_joypad_vector. x * player.scale.x, last_joypad_vector.y)
func _input(event):
# Joypad
var joypad_vector = Input.get_vector("look_left", "look_right", "look_up", "look_down")
if joypad_vector != Vector2.ZERO:
last_device = AimDevice.JOYPAD
last_joypad_vector = joypad_vector
# Mouse
if event is InputEventMouseMotion:
last_device = AimDevice.MOUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment