GameController JoyStick

I am trying to write code that uses a joystick to access various places on the screen.

The problem is the coor returned when moving match an oval, not a square…
this means that the coordiantes outside the oval are not reachable

anyone have an equation where I can take the joystick coors and re-map to the whole rectangle?

sample

the joystick stays inside the blue circle, but I need to cover the red square

make circle bigger or projection map it

Why would you use the coordinates that went outside the square?

Haven’t worked out the math yet, but the raw values from the joystick are -1 to +1

So I should be able to take those values and useing sin and cos map them to linear values

I THINK

I mean, yes, but also

  • If Coordinates outside red square, Then Ignore;

  • if you are using the joystick like a mouse, you can just use vectors. Direction and movement, instead of 1:1 mapping

  • I’d use the c# function FromPolar, but if you’re using swift I think you can use the vDSP convert function.

Can you take the lazily-ported-game approach and turn the joystick input into directional control of a mouse cursor? With any modern sized screen absolute coordinates from joystick input is going to be *extremely* sensitive and difficult to control.

1 Like

Joystick is literally giving you a direction and a velocity. If you want to use it like a mouse, you’d use that directly. That’s why its range is -1 to +1.

If you want to map it 1:1, use a projection map: the same way a globe becomes a paper map. Assuming you’re using swift I’m pretty sure there’s functions that do it for you.

but if you’re looking for a quick way to do 1:1, you could also make the circle bigger (multiply axis by screen resolution), and then in your mouse moving code, *if* input is greater than or less than the screen bounds *then* ignore, *else* position mouse at x,y

But like @Tim mentioned, 1:1 mapping is likely gonna suck. If you map it, some areas will move faster than others. If you expand it and crop it, you still a lack of precision. An equation will not give a good result here.

If this is for your solitaire game on the apple tv, you really should go with direction and velocity, unless aiming for a card is intended to be some kind of hard core difficulty mode.

Especially since for most joysticks, you will have to consider deadzones. Most people don’t have controllers with hall-effect sensors, so your inputs may be a little off, or bouncy. Controlling with the joystick directly is going to result in the cursor jiggling on the screen when not touching it.

Another option is having direct movement to targets. You can use solitaire games for the gameboy as an example.

But perhaps I just don’t seem to understand the requirements.

You have a team, right? Your team would have a much better context than we seem to have, or would have pointed this out if you ran it by them.

Dave, I think Abbie means expand the oval so it’s outside the box, then ignore the parts outside the square.

So the top might not be -1 or +1 but instead something like .8 or -.8.

1 Like

there are many ways to circle square a cat. If it works for you, it works.

You might want to look at Schwarz-Christoffel Mapping? Theres a lot of other options/explanations here: https://arxiv.org/pdf/1509.06344


Outside people reading this tho :rofl: :rofl: :rofl:

Original thread: GameController JoyStick - Swift - If Not Nil

That is simply math. And in my eyes the best way to use the Stick. But. The behavior of the Stick isn’t linear. That you have to know using Schwarz-Christoffel mapping. If you can accept it it is your method while using the entire abilities of the Joystick.