Page 2 of 2

Re: Virtual gamepad

Posted: Wed Feb 14, 2024 2:36 pm
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!

Re: Virtual gamepad

Posted: Wed Feb 14, 2024 5:12 pm
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.

Re: Virtual gamepad

Posted: Mon Feb 19, 2024 11:03 am
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 2715 times
https://codeberg.org/glitchapp/gravitonik

https://codeberg.org/glitchapp/virtual-gamepad

Re: Virtual gamepad

Posted: Thu Feb 29, 2024 5:54 am
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.

Re: Virtual gamepad

Posted: Fri Mar 01, 2024 3:42 am
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

Re: Virtual gamepad

Posted: Fri Mar 01, 2024 6:10 am
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!

Re: Virtual gamepad

Posted: Fri Mar 01, 2024 6:30 am
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.

Re: Virtual gamepad

Posted: Sat Mar 02, 2024 2:11 am
by SugarRayLua
Yes, @glitchapp, much better-- pretty smooth now!

Re: Virtual gamepad

Posted: Wed Mar 13, 2024 1:13 pm
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 2053 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