0 votes

So the default setup has some issues with inputs stoping when an action is assigned to multiple inputs, described here: #48180 #45628 and I'm trying to figure out a workaround for movement. I've made separate key binds for directions for keyboard and for gamepad. And just coded it in the most straightforward way:

var direction = Vector3.ZERO
var gamepad = Vector3.ZERO
var keyboard = Vector3.ZERO

gamepad.x = Input.get_axis("ps_left", "ps_right")
gamepad.z = Input.get_axis("ps_up", "ps_down")
keyboard.x = Input.get_axis("ui_left", "ui_right")
keyboard.z = Input.get_axis("ui_up", "ui_down")

if gamepad.x != 0: direction.x = gamepad.x
if gamepad.z != 0: direction.z = gamepad.z
if keyboard.x != 0: direction.x = keyboard.x
if keyboard.z != 0: direction.z = keyboard.z

It works but it doesn't feel very clean. I should probably just leave it like that since it works, but I feel like there's some clever way of doing it that I don't know.

Godot version 3.5.1.stable
in Engine by (62 points)

1 Answer

+1 vote
Best answer
var direction:Vector2
var gamepad  = Vector2(
var keyboard = Vector2(
if gamepad:  direction = gamepad
if keyboard: direction = keyboard

Could maybe work if that's what you mean?

by (997 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.