Gamepad axis missing?

http://html5gamepad.com/

I can’t seem to find where axis information is available.

I have all gamepad inputs detected in input binding, and it detects rstick_right etc. when moving the sticks but cannot find axis information which is what we need.

not sure that understand the question.
My gamepad works fine in this test. Also gamepads are not supported in Defold HTML5 bundle. We talked about it here:

Didn’t mean for HTML5 build but for desktop build in general.

How are you detecting axis movement? It should be a number between -1 and 1 for each of the four on an xbox 360 controller.

Edit: Ah, the axis information is action.value still trying to figure out how to best work with it… any tips? Seems like you need to detect for all combinations of gamepad_rstick_down/left/right/up + action.value + action.gamepad or is there a better way? Current design makes up keep track of 8 0 to 1 values instead of 4 -1 to 1 values?

Hmm… why are axis inputs still reported even if they go below the deadzone set in .gamepads file? I guess that makes it more convenient to filter custom deadzone at runtime…

I’m going to do something like this to get the axis value back

	if action_id == hash("gamepad_rstick_up") then
		self.axis_3 = action.value
	end
	if action_id == hash("gamepad_rstick_down") then
		self.axis_3 = action.value * -1
	end	

Again, check my Tank Vs Meteors!

function on_input(self, action_id, action)
	-- Left stick - tank's rotation/movement.
	if action_id == hash('gamepad-lstick-left') then
		self.turn = -action.value
	elseif action_id == hash('gamepad-lstick-right') then
		self.turn = action.value
	elseif action_id == hash('gamepad-lstick-down') then
		self.velocity = -action.value
	elseif action_id == hash('gamepad-lstick-up') then
		self.velocity = action.value
		
	-- Right stick - turret's rotation.
	elseif action_id == hash('gamepad-rstick-left') then
		self.turret_turn = -action.value
	elseif action_id == hash('gamepad-rstick-right') then
		self.turret_turn = action.value
		
	-- WASD keys - tank's rotation/movement.
	elseif action_id == hash('key-a') then
		if action.pressed then
			self.turn = -1
		elseif action.released then
			self.turn = 0
		end
	elseif action_id == hash('key-d') then
		if action.pressed then
			self.turn = 1
		elseif action.released then
			self.turn = 0
		end
	elseif action_id == hash('key-s') then
		if action.pressed then
			self.velocity = -1
		elseif action.released then
			self.velocity = 0
		end
	elseif action_id == hash('key-w') then
		if action.pressed then
			self.velocity = 1
		elseif action.released then
			self.velocity = 0
		end
		
	-- Left/right arrow keys - turret rotation.
	elseif action_id == hash('key-left') then
		if action.pressed then
			self.turret_turn = -1
		elseif action.released then
			self.turret_turn = 0
		end
	elseif action_id == hash('key-right') then
		if action.pressed then
			self.turret_turn = 1
		elseif action.released then
			self.turret_turn = 0
		end
		
	-- Right shoulder button or spacebar - fire.
	elseif action_id == hash('fire') and action.pressed then
		fire(self)
	-- Left shoulder button or Q key - switch the view.
	elseif action_id == hash('toggle_view') and action.pressed then
		toggle_view(self)
	end
end
4 Likes

Thanks! That seems to be the best way to do it then. I’m working on a module which can handle live game input remapping.

You should put your projects up on https://www.defold.com/community/assets/ as Assets!

also: https://github.com/britzl/publicexamples/blob/master/examples/gamepad_tester/gamepad_tester/gamepad_tester.gui_script

2 Likes

Is this even possible in Defold? To remap to different game controllers without making a new native extension?

How it works is everything is detected at once then in the game code you abstract the raw input away from the player which allows for dynamic remapping as far as the player is concerned.

1 Like

Ah, ok.