Fine, I'll Fix Mobile Controls Your Way


I had planned to pick up my game for a few minutes to playtest and brainstorm ideas for this week's stream, and then found myself distracted and just playing a few rounds of the game. That's a good sign! I was enjoying the game exactly in the way I wanted to enjoy it: as something to pick up and play a few rounds to relax and vibe. 

(Of course, the vibes will be very different once there's music and more art and whatnot, but that's for later.)

While I'd like to experiment with different mobile control schemes, the most obvious place to start is with a virtual joypad and buttons, to see how it feels on a phone. 

However, I had a problem with the joystick, and how it played with the physics that GDevelop used. 

Essentially, what I wanted was that if the joystick's angle was greater than the player's angle, it would apply torque to the player, the way pressing the D key would. If the stick angle was less than the player angle, it would apply torque in the other way, like pressing the A key. Basically, I wanted the player to always be pointing towards the direction the stick was pointing in. And then apply force - have the player accelerate - in an amount proportionate to the degree the stick is pushed. 

Those events all worked fine, except there's a thing that GDevelop does with the built-in multitouch joystick. It doesn't give its angle in 360 degrees, it gives it in 0-180 and -1 to -180. Which means that at 0 degrees and 180 degrees, the value flips from positive to negative, resulting in the direction of torque also flipping. It was not, to put it mildly, a good experience. 

The solution to this problem ended up being to not solve it. Instead, while on mobile, I used a "Rotate towards angle" action, which you can see below alongside a bunch of abandoned and disabled events that led to me trying this solution:

Basically, whenever the touch joystick is touched, it will rotate the player towards the angle the stick is at. This feels pretty good as a control method - you point the stick in the direction you want to go. 

At the same time, as you're touching the stick, it applies a force to the player proportionate with how far you're pushing the stick.

All in all, I'm actually quite happy with this implementation. It's not 1:1 the physics-based way I implemented the steering on desktop, but it works entirely as intended and it's something that I can easily replicate for a controller. 

Not only that, but it's built in a way that I can easily swap the player's car for one with different attributes and it'll work just fine.

Leave a comment

Log in with itch.io to leave a comment.