I need help creating a circle-shaped deadzone

GPC2 script programming for Titan Two. Code examples, questions, requests.

I need help creating a circle-shaped deadzone

Postby durpthesecond » Thu Dec 20, 2018 2:59 pm

Hey everyone! Basically, I was wondering what is the most efficient Titan Two code for a certain type of deadzone (see description below), that is to say, I need the code implementation that creates the lowest amount of input lag.

Description: I need the deadzone to be circle-shaped, and I need it to work like the lower graph, not like the upper graph (see the picture below). That is to say, I need to still be able to send small inputs to the console.

(P.S. For those who are curious about why I'm doing it, I'm trying to duplicate the setup that Rocket League pro players use on PC, except to make that setup available to console players too. I've already put a cross-shaped deadzone on the left stick and that worked great... now I need a circle-shaped deadzone on the right stick.)
Attachments
Stick deadzones.jpg
Stick deadzones.jpg (21.68 KiB) Viewed 727 times
User avatar
durpthesecond
Master Sergeant
Master Sergeant
 
Posts: 29
Joined: Sun Nov 25, 2018 1:53 pm

Re: I need help creating a circle-shaped deadzone

Postby J2Kbr » Fri Dec 21, 2018 3:00 pm

Hopefully I understood your request correctly, please try this:
Code: Select all
#define RADIUS      20.0
 
main {
    fix32 x = get_val(STICK_1_X);
    fix32 y = get_val(STICK_1_Y);
    fix32 radius = sqrt(x * x + y * y);
    if(radius < RADIUS) {
        set_val(STICK_1_X, 0.0);
        set_val(STICK_1_Y, 0.0);
    }
}
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: I need help creating a circle-shaped deadzone

Postby durpthesecond » Wed Dec 26, 2018 1:40 pm

Hmm... the code you wrote filters out the smallest inputs, but then suddenly jumps upwards (like the upper graph in my last post). But I was trying to make a deadzone that allows for even the smallest inputs (like the lower graph in my last post).

I'm trying to think of the math that is needed for that. Hmm...

Let "r_actual" be the actual radius, i.e. the stick's actual distance from the center.

Let "r_sent" be the stick's distance from the center that gets sent to the console (the console only gets an x value and a y value, of course, but you know what I mean).

Looking at the lower graph, and keeping in mind that the horizontal axis represents r_actual, and that the vertical axis represents r_sent, I see that the graph needs to form a line going from the point (10.0 , 0.0) to the point (100.0 , 100.0).

From that I can deduce the equation of the line over the interval 10.0 < r_actual <100.0, it is:

r_sent = (10.0/9.0)*r_actual - (100.0/9.0);

Then, using one of the laws of similar triangles to get me the right conversion factor for the x and y values, I can write the following code:

Code: Select all
 
#define RADIUS      10.0
 
main {
 
    //smooth, circular deadzone
 
    fix32 x_actual = get_actual(STICK_1_X);
    fix32 y_actual = get_actual(STICK_1_Y);
    fix32 r_actual = sqrt(x_actual * x_actual + y_actual * y_actual);
 
    if(r_actual < RADIUS)
    {
        set_val(STICK_1_X, 0.0);
        set_val(STICK_1_Y, 0.0);
    }
    else
    {
        fix32 r_sent = (10.0/9.0)*r_actual - (100.0/9.0);
        fix32 x_sent = clamp( (x_actual * (r_sent/r_actual)), -100.0, 100.0);
        fix32 y_sent = clamp( (y_actual * (r_sent/r_actual)), -100.0, 100.0);
        set_val(STICK_1_X, x_sent);
        set_val(STICK_1_Y, y_sent);
    }
 
}
 


This code seems to work correctly when I test it in the device monitor. But I don't know much about programming, I just sort of threw this together, and hence, I am not sure if the code is horribly inefficient, and if it's creating way more input lag than it needs to. So if you could tell me what is the most efficient code that does exactly the same thing as that code, then that would be greatly appreciated = )
User avatar
durpthesecond
Master Sergeant
Master Sergeant
 
Posts: 29
Joined: Sun Nov 25, 2018 1:53 pm

Re: I need help creating a circle-shaped deadzone

Postby J2Kbr » Thu Dec 27, 2018 10:35 am

Your code is good, i have just added an extra logic to avoid processing if the inputs have not changed:

Code: Select all
#define RADIUS      10.0
 
main {
    static fix32 x_prev, y_prev;
    static fix32 x_sent, y_sent;
 
    fix32 x_actual = get_actual(STICK_1_X);
    fix32 y_actual = get_actual(STICK_1_Y);
 
    if(x_actual != x_prev || y_actual != y_prev) {
        x_prev = x_actual;
        y_prev = y_actual;
 
        // smooth, circular deadzone
 
        fix32 r_actual = sqrt(x_actual * x_actual + y_actual * y_actual);
 
        if(r_actual < RADIUS)
        {
            x_sent = 0.0;
            y_sent = 0.0;
        }
        else
        {
            fix32 r_sent = (10.0 / 9.0) * r_actual - (100.0 / 9.0);
            x_sent = clamp( (x_actual * (r_sent / r_actual)), -100.0, 100.0);
            y_sent = clamp( (y_actual * (r_sent / r_actual)), -100.0, 100.0);
        }
    }
 
    set_val(STICK_1_X, x_sent);
    set_val(STICK_1_Y, y_sent);
}
 
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: I need help creating a circle-shaped deadzone

Postby durpthesecond » Fri Dec 28, 2018 11:57 am

Nice! = D Thank you so much, works like a charm = )
User avatar
durpthesecond
Master Sergeant
Master Sergeant
 
Posts: 29
Joined: Sun Nov 25, 2018 1:53 pm

Re: I need help creating a circle-shaped deadzone

Postby Apok » Sun Dec 30, 2018 4:17 pm

durpthesecond wrote: I've already put a cross-shaped deadzone on the left stick and that worked great...


Can you please post the code you have to do the left stick cross shaped dead zone please.
User avatar
Apok
Staff Sergeant
Staff Sergeant
 
Posts: 14
Joined: Sun Dec 30, 2018 12:40 am

Re: I need help creating a circle-shaped deadzone

Postby durpthesecond » Fri Feb 15, 2019 5:06 pm

Sorry I'm replying so late, it's not because I was ignoring you, just because I come here very rarely = P

But yeah, here is the code that you asked for:
viewtopic.php?f=26&t=10983
User avatar
durpthesecond
Master Sergeant
Master Sergeant
 
Posts: 29
Joined: Sun Nov 25, 2018 1:53 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: Baidu [Spider] and 160 guests