Last active
December 7, 2021 08:29
-
-
Save oronbz/1a75946a76516aa1aead622e667ca311 to your computer and use it in GitHub Desktop.
Joypad support for 1-bit-godot Metroidvania by heartbeast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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