What's up with gamepad axes?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

What's up with gamepad axes?

Post by Bobble68 »

Hi there, I am once again meandering into the love forums with a question.

So I decided it would be neat to look into controller support for my game, so I made a quick test project to try out joysticks, however I got some weird results.

The project is pretty simple - draw a circle based on the axis values, and also draw a point on a canvas behind you, which has resulted in this image when just moving the stick in a circle:
test.png
test.png (17.25 KiB) Viewed 1672 times
What's the deal with this? I would have expected either a perfect circle or a square, but not this? It's not even consistent with where it draws the line. My code is as follows:

Code: Select all

function love.load()
  circle = {}
  circle.x = 0
  circle.y = 0
  
  
  love.window.setMode(0,0)  
  joysticks = love.joystick.getJoysticks()
  joystick = joysticks[1]
  drawCanvas = love.graphics.newCanvas()
  
end


function love.update(dt)
  joysticks = love.joystick.getJoysticks()
  
  joystick = joysticks[1]
  
  local distance = 500
  if joystick and joystick:isGamepad() then
    circle.x = joystick:getGamepadAxis("leftx")*distance
    circle.y = joystick:getGamepadAxis("lefty")*distance
  end
end


function love.draw() 
  if joystick and joystick:isGamepad() then
    love.graphics.setBackgroundColor(0,0,0)
  else
    love.graphics.setBackgroundColor(1,0,0)
  end
  
  drawCanvas:renderTo( 
    function()
      love.graphics.circle("fill", circle.x+love.graphics.getWidth()/2, circle.y+love.graphics.getHeight()/2, 1)
    end
    )

  love.graphics.circle("line", circle.x+love.graphics.getWidth()/2, circle.y+love.graphics.getHeight()/2, 50)
  love.graphics.draw(drawCanvas,0,0)
end



function love.keypressed(key)
  if key == "escape" then
    love.event.quit()
  end
end


Dragon
User avatar
BrotSagtMist
Party member
Posts: 665
Joined: Fri Aug 06, 2021 10:30 pm

Re: What's up with gamepad axes?

Post by BrotSagtMist »

Well its obvious, a joystick is made up from two angle detectors within a round hole.
On consoles games compensate for that by applying scaling and deadzones.
On PC this settings should be added via OS and likely no one ever does them so its up to you to support all the 40000 possible gamepads that all have their own calibration.
Just saying, dont bother, you simly cannot expect a gamepad to be remotely accurate.
obey
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: What's up with gamepad axes?

Post by Bobble68 »

BrotSagtMist wrote: Fri Apr 28, 2023 2:12 pm On PC this settings should be added via OS and likely no one ever does them so its up to you to support all the 40000 possible gamepads that all have their own calibration.
Just saying, dont bother, you simly cannot expect a gamepad to be remotely accurate.
How hard could it be? I reckon I could automatically calibrate it to give a circle.
Dragon
User avatar
darkfrei
Party member
Posts: 1216
Joined: Sat Feb 08, 2020 11:09 pm

Re: What's up with gamepad axes?

Post by darkfrei »

I have this picture with this file:

Image


https://github.com/darkfrei/love2d-lua- ... ut-03.love
Attachments
controller-input-03.png
controller-input-03.png (21.64 KiB) Viewed 1645 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: What's up with gamepad axes?

Post by Bobble68 »

darkfrei wrote: Fri Apr 28, 2023 2:51 pm I have this picture with this file:

Image


https://github.com/darkfrei/love2d-lua- ... ut-03.love
Ooooh that's interesting, I get much the same as my first image with your program (but with double the fun!). Surely there must be some standardised way of dealing with this? Controllers aren't exactly niche.
test.png
test.png (26.41 KiB) Viewed 1639 times
Last edited by Bobble68 on Fri Apr 28, 2023 3:01 pm, edited 1 time in total.
Dragon
User avatar
darkfrei
Party member
Posts: 1216
Joined: Sat Feb 08, 2020 11:09 pm

Re: What's up with gamepad axes?

Post by darkfrei »

Bobble68 wrote: Fri Apr 28, 2023 2:56 pm
darkfrei wrote: Fri Apr 28, 2023 2:51 pm I have this picture with this file:

Image


https://github.com/darkfrei/love2d-lua- ... ut-03.love
Ooooh that's interesting, I get much the same as my first image with your program (but with double the fun!). Surely there must be some standardised way of dealing with this? Controllers aren't exactly niche.
Your square is software limited, but the circle has mechanical limitations, it looks like the stick cannot me moved to the end position.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: What's up with gamepad axes?

Post by Bobble68 »

darkfrei wrote: Fri Apr 28, 2023 3:00 pm Your square is software limited, but the circle has mechanical limitations, it looks like the stick cannot me moved to the end position.
How odd, it's a fairly decent controller.
Dragon
User avatar
darkfrei
Party member
Posts: 1216
Joined: Sat Feb 08, 2020 11:09 pm

Re: What's up with gamepad axes?

Post by darkfrei »

Bobble68 wrote: Fri Apr 28, 2023 3:04 pm
darkfrei wrote: Fri Apr 28, 2023 3:00 pm Your square is software limited, but the circle has mechanical limitations, it looks like the stick cannot me moved to the end position.
How odd, it's a fairly decent controller.
My was the cheapest https://www.amazon.de/gp/product/B075SJ3NJ6 and works pretty well.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
BrotSagtMist
Party member
Posts: 665
Joined: Fri Aug 06, 2021 10:30 pm

Re: What's up with gamepad axes?

Post by BrotSagtMist »

Given a circle one could apply calibration, not too hard.
But my point here was mostly that most arent exactly made for fine circle movements anyway.
Most games you either have left/right or up/down movements, booth together are rare so it kanda makes sense to neglegt the mapping for diagonials.
obey
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: What's up with gamepad axes?

Post by Bobble68 »

BrotSagtMist wrote: Fri Apr 28, 2023 3:16 pm Given a circle one could apply calibration, not too hard.
But my point here was mostly that most arent exactly made for fine circle movements anyway.
Most games you either have left/right or up/down movements, booth together are rare so it kanda makes sense to neglegt the mapping for diagonials.
Yeah my game has diagonals, though as long as it gets the general direction correct it should be fine... I think. I should probably test it
Dragon
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests