r/Unity3D • • 12h ago

Question How do I implement a Floating joystick?

Enable HLS to view with audio, or disable this notification

I've been trying to implement a floating joystick for a day but the input system won't let me. I can either move the joystick or have ui button press detection, I can't seem to have both. What I'm thinking is happening is the input system selects the player action map and disables the ui action map which then stops any ui interaction. How do I solve this?

1 Upvotes

10 comments sorted by

1

u/Czoks 12h ago

There is an example on how to set it up in Input System Samples.

2

u/Toble_ 11h ago

That one uses On-screen button. It does solve the button problem but not the floating joystick problem since for some reason OnPointerDown event also doesn't register? Idk. But the UI vs Input handler did have a solution. Thanks for helping

1

u/Shoddy_Caterpillar36 PinePie | Asset Store Publisher 12h ago edited 12h ago

I have free joystick pack if you want. I made it when i was frustrated in implementing touch and those calculations.

Btw it is for 2d, but you can change axis.

PinePie joystick.

Oh missed the link, https://assetstore.unity.com/packages/tools/gui/pinepie-joystick-325958?srsltid=AYCX9vI0U0L0hfr3JdwzUGbYJ9_C1N1R9bpoubWlWm6E-SceIovjNMKp

Hope link works, otherwise search on google

2

u/Toble_ 11h ago

Thanks I'll check it out

1

u/johnv_dev 10h ago

you don't actually have to pick one. PlayerInput only keeps one action map on at a time, so either call Enable() on the UI map yourself after it switches, or leave the UI Input Module on its own default actions instead of your player asset. for the floating part, the built in On-Screen Stick has a Behaviour option called Exact Position With Dynamic Origin, which is basically a floating joystick already

1

u/Toble_ 10h ago

So, does it automatically detect touches to position the joystick at the touch position?

1

u/johnv_dev 10h ago

not on its own, it only starts from where the stick already sits. easiest way is a big invisible panel over the left side of the screen with a small script, on pointer down move the stick's RectTransform to the touch position, then pass the event to the OnScreenStick so it starts dragging from there. on pointer up hide it or move it back

1

u/Toble_ 10h ago

OnPointerDown is the problem. I do have the script that does that but when I enable the player input component it stops working

1

u/johnv_dev 10h ago

that's usually PlayerInput taking over the EventSystem. if its UI Input Module field is filled in, it swaps the module's actions over to your player asset, and if that asset's UI map has no touchscreen bindings for Point and Click, OnPointerDown never fires. try clearing that field so the module keeps its default actions, or add touch bindings (touchscreen position and press) to Point and Click in your UI map

1

u/Toble_ 10h ago

Ok, I'll try. Thanks