I need help with creating a cross-shaped deadzone

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

Re: I need help with creating a cross-shaped deadzone

Postby durpthesecond » Tue Dec 11, 2018 9:04 am

Thanks so much = D

Oh and to answer your question... yes, the game lets you set the real deadzone to almost nothing (I barely move the stick and see a tiny input happen in the game).
User avatar
durpthesecond
Master Sergeant
Master Sergeant
 
Posts: 29
Joined: Sun Nov 25, 2018 1:53 pm

Re: I need help with creating a cross-shaped deadzone

Postby teckx » Tue Mar 26, 2019 7:19 pm

would this help with anti recoil?
User avatar
teckx
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 194
Joined: Tue Mar 27, 2018 1:53 pm

Re: I need help with creating a cross-shaped deadzone

Postby Beryl » Thu Aug 31, 2023 5:27 pm

Can anyone add an anti recoil script to this? Game im playing is pubg



J2Kbr wrote:this will require some math, please test:
Code: Select all
#define DEADZONE_X      20.0
#define DEADZONE_Y      20.0
#define DEADZONE_D      4.0 // Cross Shape Deadzone
 
void deadzone() {
    static fix32 ax, ay;
    static fix32 vx, vy;
    if(ax != get_actual(STICK_1_X) || ay != get_actual(STICK_1_Y)) {
        vx = ax = get_actual(STICK_1_X);
        vy = ay = get_actual(STICK_1_Y);
 
        fix32 sx = (vx < 0.0) ? (vx = inv(vx), -1.0) : (vx > 0.0) ? 1.0 : 0.0;
        fix32 sy = (vy < 0.0) ? (vy = inv(vy), -1.0) : (vy > 0.0) ? 1.0 : 0.0;
 
        fix32 a = atan2(vy, vx);
        fix32 dx = DEADZONE_X * pow(cos(a), DEADZONE_D);
        fix32 dy = DEADZONE_Y * pow(sin(a), DEADZONE_D);
 
        if(vx <= dx) vx = 0.0;
        if(vy <= dy) vy = 0.0;
 
        vx *= sx;
        vy *= sy;
    }
    set_val(STICK_1_X, clamp(vx, -100.0, 100.0));
    set_val(STICK_1_Y, clamp(vy, -100.0, 100.0));
    return;
}
 
main {
    deadzone();
}
 
User avatar
Beryl
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 198
Joined: Fri Nov 27, 2020 7:47 pm

Re: I need help with creating a cross-shaped deadzone

Postby MrBrgv » Tue Sep 05, 2023 7:12 pm

Not My Anti_Recoil


Code: Select all
#define DEADZONE_X      20.0
#define DEADZONE_Y      20.0
#define DEADZONE_D      4.0 // Cross Shape Deadzone
 
// Anti_Recoil----------------------------------
fix32 RECOIL_V = -40.0;
fix32 RECOIL_H = 0.0;
fix32 RY;
fix32 RX;
 
 
main {
    deadzone();
     if (get_val (BUTTON_5))
    {   
        AntiRecoil(STICK_1_Y,RECOIL_V);
        AntiRecoil(STICK_1_X,RECOIL_H);
    }
 
 
}
 
 
void AntiRecoil (uint8 axis, fix32 recoil)
{
     RY = get_actual(STICK_1_Y);
     RX = get_actual(STICK_1_X);
 
    if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
    {
        if(abs(RY) <= abs(recoil))
        {
            set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
        }
    }
}
 
 
 
void deadzone() {
    static fix32 ax, ay;
    static fix32 vx, vy;
    if(ax != get_actual(STICK_1_X) || ay != get_actual(STICK_1_Y)) {
        vx = ax = get_actual(STICK_1_X);
        vy = ay = get_actual(STICK_1_Y);
 
        fix32 sx = (vx < 0.0) ? (vx = inv(vx), -1.0) : (vx > 0.0) ? 1.0 : 0.0;
        fix32 sy = (vy < 0.0) ? (vy = inv(vy), -1.0) : (vy > 0.0) ? 1.0 : 0.0;
 
        fix32 a = atan2(vy, vx);
        fix32 dx = DEADZONE_X * pow(cos(a), DEADZONE_D);
        fix32 dy = DEADZONE_Y * pow(sin(a), DEADZONE_D);
 
        if(vx <= dx) vx = 0.0;
        if(vy <= dy) vy = 0.0;
 
        vx *= sx;
        vy *= sy;
    }
    set_val(STICK_1_X, clamp(vx, -100.0, 100.0));
    set_val(STICK_1_Y, clamp(vy, -100.0, 100.0));
    return;
}
 
User avatar
MrBrgv
Sergeant First Class
Sergeant First Class
 
Posts: 16
Joined: Sun Dec 27, 2020 9:32 pm

Previous

Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 43 guests