#Joystick in Unity 2D for a mobile player controller

1 messages · Page 1 of 1 (latest)

worthy plinth
#

Hi there, im trying to make a simple player controller for a mobile game using a joystick. Ive tried both the old input system and the new input system but I cant seem to get anything to work. Ive tried for 2 days starting from the ground up and done way too much googling on how to create one but havent found a solution to my problem. Would anyone be kind enough to teach me how to set this sort of thing up? Im at a loss here and I really dont know where else to go

bright crystal
#

joystick as in two circles u can touch and drag on the sides of screen?

worthy plinth
#

Yes but rather one joystick in the bottom center. I'm building a portrait game

#

I've gone through so many different tutorials out there and I can't get a single one to work

bright crystal
#

oh I was in hell few months ago when I was doing two circles on the sides same stuff everything is either not suitable for me or barely functioning kekW gl with the thread bro been there

#

I just did my own solution tracking initial touch location then direction where touch moved + distance towards it and acted upon it

worthy plinth
#

Interesting.... That's not a bad idea

#

Something like

public GameObject joystick;
private Vector2 touchPos;
private Vector2 dragPos;

touchPos = joystick.transfom.position;

Then subtract the touchPos from the dragPos to get distance travelled

Something like that

Multiply the distance travelled on the joystick and multiply it to get a more accurate movement for the player itself

#

And then how would I get the direction? Since there isn't rotation

#

The player is basically in an infinite plane so I really just need to be able to move the player

#

In the same direction as the joystick

bright crystal
#

Let me get on pc to maybe write something up

worthy plinth
#

Thanks man it's v much appreciated

bright crystal
#

yea so keep in mind im aint even good so without testing myself im prolly missing something but its a start kekW https://hatebin.com/qiolfpqevb with this you would have all 3 things you would need, if IsTouching is true then you can depending on what u got move ur player with CurrentDirection * DistanceFromInitialTouch but needs a clamp for max speed