A brand new game
for Windows, HTML5, iPhone, Android TV and more,
every week,
unless exhausted!
Joystick code
  24th December, 2017
A bit of blind coding, last night.


I woke up at 1am, wide awake, and couldn't get back to sleep.
I sat playing Mario Odyssey for .. a good couple of hours!

After that, I decided to do the "quick" fix for the joystick code.

The main issue was I was lazily doing x/y values separately, which "almost" works, but has issues when the thumbstick is near the four compass directions.
Because the code is ignoring the stick when it's in the "Dead-zone", it completely ignores minor angles when the thumbstick is at the extents of the opposite axis..

Imagine you hold directly-up, but then nudge ever so slightly to the left.
Because the X value is so minor, it would get ignored completely, as the code thinks it's still within the deadzone.

Instead, I had to work out whether the distance of BOTH co-ords are outside of the deadzone, and THEN send those co-ords to the functions.
A simple Pythagoras does the trick..
If ((x*x)+(y*y))> DeadZone...

I've done this half-a-dozen times in the past, and I'm not sure why I didn't bother to do it this time. But now I have, so that's good!

A nice and quick code tweak, but something I couldn't test without a nearby joystick at hand, since I'd left them all downstairs, and by this point it was 4 in the morning!!

This morning, I checked, and it does indeed seem to be functioning, but I still haven't added an option to invert the Y's, so it's still wrong using my Xbox pads.

I really need to do that, next.
But Festive Jay is relaxing without coding. .. apparently!

Views 25, Upvotes 3, 24th December, 2017
Daily Blog , 2018 Framework
Site credits : All of the above : Jayenkai
(c) Jayenkai 2017 and onwards.
Blog - Joystick code - AGameAWeek