Page 1 of 2

What's up with gamepad axes?

Posted: Fri Apr 28, 2023 1:46 pm
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 1670 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



Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 2:12 pm
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.

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 2:28 pm
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.

Re: What's up with gamepad axes?

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

Image


https://github.com/darkfrei/love2d-lua- ... ut-03.love

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 2:56 pm
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 1637 times

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 3:00 pm
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.

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 3:04 pm
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.

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 3:09 pm
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.

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 3:16 pm
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.

Re: What's up with gamepad axes?

Posted: Fri Apr 28, 2023 3:39 pm
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