Virtual gamepad

Show off your games, demos and other (playable) creations.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: Virtual gamepad

Post by SugarRayLua »

Found the post-- sounds great!

Happy to take a look at some of those games and see if can get some working on mobile 😊👍, thanks!
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Virtual gamepad

Post by glitchapp »

SugarRayLua wrote: Wed Feb 14, 2024 2:36 pm Found the post-- sounds great!

Happy to take a look at some of those games and see if can get some working on mobile 😊👍, thanks!
Thanks SugarRayLua, that's great. I will try to implement any solution based on the feedback received. Hopefully the list will improve over time.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Virtual gamepad

Post by glitchapp »

I added a third layout which is a virtual keyboard. The first game to implement this layout is Gravitonik which you can now play on your mobile:
keyboardTouch.gif
keyboardTouch.gif (401.19 KiB) Viewed 4806 times
https://codeberg.org/glitchapp/gravitonik

https://codeberg.org/glitchapp/virtual-gamepad
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Virtual gamepad

Post by glitchapp »

I've recently started a function to provide network functionality to the touch library. The main function in charge of that feature is here: https://codeberg.org/glitchapp/virtual- ... ckAxes.lua
Basically the data should be transmitted over UDP to another instance and retrieve through the variables:

Code: Select all

receivedLeftXAxis = 0
receivedLeftYAxis = 0
receivedRightXAxis = 0
receivedRightYAxis = 0
This will open the possibility of easily making games multiplayer and even over the internet (although for latency sensible games it may not work).
Beware that the function "releaseJoystickButtons" in charge of receiving the release data from a real controller interfere with the touch controls and needs to be commented if you don't plan to use a real gamepad so that the touch buttons react

Code: Select all

if joystick then
        assignRealGamepadAxisToVirtualAxis()    -- assign real Gamepad values to virtual gamepad
        releaseJoystickButtons(joystick, button) -- Release joystick buttons
    end
Feel free to test it and let me know what you think, and of course feel free to contribute if you have ideas on how to improve this feature.
Attachments
TouchControls-0.1-5.love
(1.07 MiB) Downloaded 279 times
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: Virtual gamepad

Post by SugarRayLua »

Coming along nicely, @glitchapp!

Only thing I notice is that as move virtual joystick from one extreme to the other (e.g. from far left of center to far right of center) the joystick moves as if it were moving through a gearshift box (i.e. as I drag the joystick it seems to "jump" from farthest left to a position not quite as far left to center to a position mid to right of center to extreme right as opposed to rendering a smooth transition from one extreme position to the other). If I rotate the virtual joystick in a circular position, the app rotates the circular movement smoothly. Not sure if that "gearshift" life side to side and up to down movement of the joystick is what you were intending; other virtual joysticks instead render side to side and up to down movement as a smooth continuous movement.

Fyi 😊
VirtualJoystick.webm
(1.17 MiB) Not downloaded yet
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Virtual gamepad

Post by glitchapp »

SugarRayLua wrote: Fri Mar 01, 2024 3:42 am Coming along nicely, @glitchapp!

Only thing I notice is that as move virtual joystick from one extreme to the other (e.g. from far left of center to far right of center) the joystick moves as if it were moving through a gearshift box (i.e. as I drag the joystick it seems to "jump" from farthest left to a position not quite as far left to center to a position mid to right of center to extreme right as opposed to rendering a smooth transition from one extreme position to the other). If I rotate the virtual joystick in a circular position, the app rotates the circular movement smoothly. Not sure if that "gearshift" life side to side and up to down movement of the joystick is what you were intending; other virtual joysticks instead render side to side and up to down movement as a smooth continuous movement.

Fyi 😊
VirtualJoystick.webm
Thanks for the feedback SugarRayLua,
No it is not intended, it's the first time I try to make a virtual thumbstick and I'm using some ideas I used for a radial menu... I think what you are telling me is caused by the threshold.

Code: Select all

-- Update the existing updateThumbstickAxes function to update left thumbstick axes
function touchControls:updateLeftThumbstickAxes(x, y)
  local relativeX = x - self.leftThumbstickX
  local relativeY = y - self.leftThumbstickY
  local length = math.sqrt(relativeX^2 + relativeY^2)

  if length <= self.leftThumbstickRadius then
    self.leftxaxis = relativeX / self.leftThumbstickRadius
    self.leftyaxis = relativeY / self.leftThumbstickRadius
  else
    local scaleFactor = self.leftThumbstickRadius / length
    self.leftxaxis = relativeX * scaleFactor
    self.leftyaxis = relativeY * scaleFactor
  end
In this code block, if the length of the vector (length) is less than or equal to the thumbstick radius (self.leftThumbstickRadius), it means the thumbstick is within the threshold. If it's beyond that radius, then it's considered beyond the threshold.

I need to keep tweaking all of those parameters and also the size of the thumstick and buttons to find out how to make it more smooth and comfortable.

I don't make releases as oft as updates so if anyone is interested on testing the last tweaks I do to this library feel free to fork the repository and do git pull. I will try to find out the right parameters with your feedback and some experimentation, I hope I manage to get it right!
Last edited by glitchapp on Fri Mar 01, 2024 6:31 am, edited 1 time in total.
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Virtual gamepad

Post by glitchapp »

I think I solved that problem, feel free to test it and let me know if it is right now.

I still need to adjust other parameters but I think it starts to feel right and react like a real thumbstick does.
Attachments
TouchControls-0.1-6.love
(1.07 MiB) Downloaded 324 times
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: Virtual gamepad

Post by SugarRayLua »

Yes, @glitchapp, much better-- pretty smooth now!
glitchapp
Party member
Posts: 264
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Virtual gamepad

Post by glitchapp »

I've recently released a new version of the touch controls which introduces remote network capabilities.
gamepad.gif
gamepad.gif (559.38 KiB) Viewed 4144 times
The extra circles on top of the gamepad represents the thumbstick of the remote instance (and reacts to the receiving movement from that instance)

To test it all that is needed is to set up the Ip address of the receiving and sending instance on src/Network/sendAxes.lua and to open two instances of the controls and press "2" on one of them.

You can even test that functionality on the same computer, just make sure you set up the same ip for both the receiving and sending instance.

I'm sharing here because there is still a big problem: the lag make it almost useless for arcade or any game that requires fast response, this happens even through local network. I'm not sure how to solve that so just in case anyone knows and want to test it here is the preliminary demo.

* I forgot to mention that this new version can also be used with a real gamepad (without using the touch controls)

* Problem with lag is solved: I called send axes twice by mistake causing the lag, at least on local network now it is perfectly usable even for arcade games
Attachments
TouchControls-0.1-7.love
(1.22 MiB) Downloaded 273 times
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Majestic-12 [Bot] and 3 guests