[PLUGIN] AGS Controller Support (OPEN SOURCE) - v1.1

Started by Dualnames, Tue 30/04/2019 03:20:35

Previous topic - Next topic

Snarky

Couldn't you make the stick control the movement of the cursor rather than its absolute position directly?

Something like:

Code: ags
      Mouse.SetPosition(mouse.x + axisCo2, mouse.y + axisCo3);

AndreasBlack

#41
Edit: My bad, i was wrong  (laugh)


Snarky

I'm sorry, but it will work. The numbers will have to be scaled and bounded, but this is how controlling movement vs. controlling position is done.

deadsuperhero

Quote from: Snarky on Fri 29/04/2022 09:44:07
Couldn't you make the stick control the movement of the cursor rather than its absolute position directly?

I think you're on the right track, this does seem to be an improvement of sorts...
One thing that I've noticed with this plugin: the axis values never seem to be zero with my controller. I'm not sure if this is a bug in the plugin or my drivers, or just how controllers are in general, but my PS5 DualSense controller always registers as a non-zero number, even when the sticks aren't moving.

I'm going to keep trying to debug this on my end, it could just be that something in my setup is giving me an unnecessary headache. I just can't figure out how to represent a "joystick at rest" setting so that the game engine knows not to move the cursor any further. Right now, it just kind of slowly drifts all over the place.
The fediverse needs great indie game developers! Find me there!

Snarky

You could just set it to 0 if the absolute value is less than some threshold.

Dualnames

deadsuperhero, this is not a bug with your controller or the plugin. There is a deadzone for controllers, for instance my xbox varies from -4000 to 4000 and jiggles around these values, so u need to do a check for not 0 but for a values within the deadzone.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

deadsuperhero

Yay, I figured it out! :cheesy:
Thanks for setting me on the right path, DualNames and Snarky. <3

It turns out that I was really overthinking this a lot.

Code: ags


function deadzoneCheck() {
  // Right Stick -- Horizontal
  if (axis2 <= 2000 && axis2 >= -2000) {
    dz_horiz_left=true;
  }
  else if (axis2 > 2000 || axis2 < -2000) {
    dz_horiz_left=false;
    deadZone = "False";
  }
  
  // Right Stick -- Vertical
  if (axis3 <= 2000 && axis3 >= -2000) {
    dz_vert_left=true;
    deadZone = "True";
  }
  else if (axis3 > 2000 || axis3 < -2000) {
    dz_vert_left=false;
    deadZone = "False";
  }  
}

function trackAxis() {
  String inputName = gamepad.GetName();
  if (gamepad.Plugged() == true) {
    axis0 = gamepad.GetAxis(0); // Left Stick
    axis1 = gamepad.GetAxis(1); // Left Stick
    axis2 = gamepad.GetAxis(2); // Right Stick
    axis3 = gamepad.GetAxis(3); // Right Stick
  }
    if (inputName == "PS5 Controller") {
    axisCo2 = gamepad.GetAxis(2) / 2000; // Rate of Horizontal Motion
    axisCo3 = gamepad.GetAxis(3) / 2000; // Rate of Vertical Motion
    deadzoneCheck();
    
    
    // Stick Input
    if (dz_horiz_left == false || dz_vert_left == false){ // RIGHT STICK
      Mouse.SetPosition(mouse.x + axisCo2, mouse.y + axisCo3);
    }
   }
}


Checking for deadZone 100% fixed my problem, thanks for taking the time to educate me on best practices!
The fediverse needs great indie game developers! Find me there!

SMF spam blocked by CleanTalk