Trigger to analog stick remap for driving games

GPC1 script programming for Titan One. Code examples, questions, requests.

Trigger to analog stick remap for driving games

Postby berumsey » Fri Jun 13, 2014 10:14 pm

I need to map ps4 controller r2 to left stick y axis 0 - -100 and l2 to left stick y axis 0 - 100. In other words, left analog up is throttle and left analog down is brake. Any ideas for scripting? Also could use a ~10 deadband.
User avatar
berumsey
Corporal
Corporal
 
Posts: 4
Joined: Fri Jun 13, 2014 8:33 pm

Re: Trigger to analog stick remap for driving games

Postby CypherNova139 » Sat Jun 14, 2014 8:21 pm

Easy enough, you'd want to set up in the main, if LY is greater than 20 (deadzone) then press R2, otherwise press L2 etc.

Here's a section from my sixaxis remapper script that you should find useful, with a few tweaks it will work for you. ;)
(I'm sure you can figure out the rest).


Code: Select all
 if(get_val(PS3_LY) > 20) {
        //down
        set_val(PS3_ACCY, get_val(StickY));
        set_val(PS3_LY, 0);
    } else {
        set_val(PS3_ACCY, get_val(StickY));
        set_val(PS3_LY, 0);
    }
User avatar
CypherNova139
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat May 10, 2014 5:11 am

Re: Trigger to analog stick remap for driving games

Postby berumsey » Sun Jun 15, 2014 4:00 am

Thank you for the tip!

My script is:
Code: Select all
unmap PS4_RX;
unmap PS4_RY;
remap PS4_RX -> PS4_LX;
remap PS4_RY -> PS4_LY;
unmap PS4_ACCX;
unmap PS4_ACCY;
unmap PS4_ACCZ;


main {
//up
     if(get_val(PS4_LY) > -10) {
            set_val(PS4_R2, 0);
        } else {
            set_val(PS4_R2, inv(get_val(PS4_LY)));
        }
//down
     if(get_val(PS4_LY) < 10) {
            set_val(PS4_L2, 0);
        } else {
            set_val(PS4_L2, get_val(PS4_LY));
        }

}


Works great!
User avatar
berumsey
Corporal
Corporal
 
Posts: 4
Joined: Fri Jun 13, 2014 8:33 pm

Re: Trigger to analog stick remap for driving games

Postby CypherNova139 » Mon Jun 16, 2014 11:34 pm

Nice! Glad to see ya figured out how to get it to work! But what is all the remap codes for?

Btw, You got me curious enough that I redid my sixaxis script after posting my first post on this thread, you might try this out too. Its a bit more complex but you can switch which stick is remapped on the fly.
User avatar
CypherNova139
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat May 10, 2014 5:11 am

Re: Trigger to analog stick remap for driving games

Postby berumsey » Thu Jun 19, 2014 8:18 pm

Had to remap the controller right stick to work the left stick output. Not only does it give me steering on right stick in nfs rivals, but menu control since the left stick y axis is now R2-L2 "gas and brake". The unmap rx and ry makes it so right stick movement doesn't output both sticks. The acc* unmaps make it ignore gyroscope input, which I would assume makes the cpu load on the cm lower and therefore run "probably imperceptibly" cooler. Make sense?
User avatar
berumsey
Corporal
Corporal
 
Posts: 4
Joined: Fri Jun 13, 2014 8:33 pm

Re: Trigger to analog stick remap for driving games

Postby CypherNova139 » Sat Jun 21, 2014 1:47 am

Ah, didn't know you were using the right stick as well, makes sense now.

FYI:
Just tested in Device Monitor the CPU load of no scripts running, and a script with JUST the sixaxis unmaps. Both kept CPU load at 9%, no perceptible difference.

But I tested the same with your script, running it, then commenting out the unmaps, then running it again..
Without the comments (aka sixaxis disabled) I got the CPU load to randomly pop to 9% instead of the usual 10%. Commented version stayed at 10%.

As far as my scripts, they average 11-15%, going to 20% occasionally if you are running the customization features. After using those scripts the CM produces about as much heat as I'd expect from a little dongle with a CPU inside. So its up to you whether you believe there is a heat difference or not from CPU load.
User avatar
CypherNova139
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat May 10, 2014 5:11 am

Re: Trigger to analog stick remap for driving games

Postby marioxb » Mon Sep 30, 2024 3:55 pm

Here is the reverse, for Nintendo Switch. Thanks to Gul Malano from Fiverr, here's a remapping script so that when ZR is pressed, it's like pushing the left analog stick up. ZL is mapped as analog down, both retaining full analog sensitivity. This is useful for getting analog pedals in driving games on Switch.

unmap SWITCH_ZL;
unmap SWITCH_ZR;

main {
// Up
if (get_val(SWITCH_ZR) > 0) { // Check if ZR is pressed
set_val(SWITCH_LY, inv(get_val(SWITCH_ZR))); } else {
set_val(SWITCH_LY, get_val(SWITCH_LY));
}

// Down
if (get_val(SWITCH_ZL) > 0) { // Check if ZL is pressed
set_val(SWITCH_LY, get_val(SWITCH_ZL)); } else {
set_val(SWITCH_LY, get_val(SWITCH_LY));
}
}
User avatar
marioxb
Corporal
Corporal
 
Posts: 5
Joined: Wed Feb 28, 2024 6:30 pm


Return to GPC1 Script Programming

Who is online

Users browsing this forum: No registered users and 25 guests