Anti-Recoil Public Release
5 posts
• Page 1 of 1
Anti-Recoil Public Release
This is still a work in progress the original code belongs to DrNefario and I used the Dead zone Removal from Antithesis.
The code has been heavily modified, features I plan on adding Randomization On Shot and a more customizable Anti-Recoil.
I'm not able to test the code for in-game functionality at the moment, but it compiles, if anyone wants to test it and give feedback that would be cool. It has comments throughout, so people can see what each part does.
The code has been heavily modified, features I plan on adding Randomization On Shot and a more customizable Anti-Recoil.
I'm not able to test the code for in-game functionality at the moment, but it compiles, if anyone wants to test it and give feedback that would be cool. It has comments throughout, so people can see what each part does.
- Code: Select all
// Define constants for vertical and horizontal recoil, and magnitude of adjustment
const fix32 RECOIL_V = 5.0;
const fix32 RECOIL_H = 1.0;
const fix32 Stick_Noise = 13.0;
// Define settings for Two Part Anti-Recoil
const fix32 SPLIT_PARAMETER = 0.3; // Radius of inner circle
const fix32 MOVEMENT_THRESHOLD = 0.9; // Radius of outer ring
// Declare scaling factor variable
fix32 scale_factor;
// Main loop
main {
if (is_active(BUTTON_5) && is_active(BUTTON_8)) { // Activates the anti-recoil system
fix32 stick_x = get_val(STICK_1_X);
fix32 stick_y = get_val(STICK_1_Y);
// Check if right stick position is within inner circle or outer ring
fix32 stick_dist = sqrt(sq(stick_x) + sq(stick_y));
if (stick_dist < SPLIT_PARAMETER) {
// No anti-recoil compensation applied within inner circle
set_val(STICK_1_X, stick_x);
set_val(STICK_1_Y, stick_y);
} else if (stick_dist < MOVEMENT_THRESHOLD) {
// Apply anti-recoil compensation to outer ring
AntiRecoil(STICK_1_Y, STICK_1_X, RECOIL_V, RECOIL_H);
// Get actual stick values
fix32 stick1_x = get_actual(STICK_1_X);
fix32 stick1_y = get_actual(STICK_1_Y);
fix32 stick2_x = get_actual(STICK_2_X);
fix32 stick2_y = get_actual(STICK_2_Y);
// Deadzone remover
set_val(STICK_1_X, abs(stick1_x) < Stick_Noise ? 0.0 : get_val(STICK_1_X));
set_val(STICK_1_Y, abs(stick1_y) < Stick_Noise ? 0.0 : get_val(STICK_1_Y));
set_val(STICK_2_X, abs(stick2_x) < Stick_Noise ? 0.0 : get_val(STICK_2_X));
set_val(STICK_2_Y, abs(stick2_y) < Stick_Noise ? 0.0 : get_val(STICK_2_Y));
}
}
}
// Function to apply anti-recoil to the right stick
void AntiRecoil(uint8 axisY, uint8 axisX, fix32 recoil_Y, fix32 recoil_X)
{
// Check if recoil exists
if (recoil_Y + recoil_X)
{
// Get actual values of right stick Y and X axis
fix32 RY = get_actual(axisY);
fix32 RX = get_actual(axisX);
// Calculate magnitude of current recoil vector
fix32 RXRY = sq(RY) + sq(RX);
// If recoil vector magnitude is smaller than or equal to adjustment magnitude,
// apply simple adjustment to stick value based on recoil and input values
if (RXRY <= sq(Stick_Noise))
{
// Calculate scaling factor
scale_factor = sqrt(sq(recoil_Y) + sq(recoil_X));
// Scale input values based on scaling factor and adjust stick value based on input value magnitude
set_val(axisY, (recoil_Y / scale_factor) * (scale_factor + Stick_Noise));
set_val(axisX, (recoil_X / scale_factor) * (scale_factor + Stick_Noise));
}
// If recoil vector magnitude is larger than adjustment magnitude,
// apply more complex adjustment to stick value based on recoil and input values
else
{
// Calculate true radius of current recoil vector and set scaling factor
fix32 true_radius = min(sqrt(RXRY), 100.0);
scale_factor = 100.0 - Stick_Noise;
// Scale input values based on current recoil vector radius
RY *= ((true_radius - Stick_Noise) / true_radius);
RX *= ((true_radius - Stick_Noise) / true_radius);
// Apply scaling factor to recoil values and adjust stick value based on input value magnitude
recoil_Y -= ((recoil_Y * 0.80) / scale_factor) * true_radius;
recoil_X -= ((recoil_X * 0.80) / scale_factor) * true_radius;
RY += recoil_Y - ((recoil_Y / scale_factor) * abs(RY));
RX += recoil_X - ((recoil_X / scale_factor) * abs(RX));
// Adjust stick value based on final adjusted input value and adjustment magnitude
scale_factor = sqrt(sq(RY) + sq(RX));
RY = (RY / scale_factor) * (scale_factor + Stick_Noise);
RX = (RX / scale_factor) * (scale_factor + Stick_Noise);
// Set clamped stick value based on final adjusted input value
set_val(axisY, clamp(RY, -100f, 100f));
set_val(axisX, clamp(RX, -100f, 100f));
}
}
return;
}
Last edited by turmoil_manpower on Tue May 23, 2023 6:07 am, edited 1 time in total.
-
turmoil_manpower - Sergeant
- Posts: 7
- Joined: Sat May 06, 2023 7:41 pm
Re: Anti-Recoil Public Release
thanks for your work, today I will try it in pubg and give comments
-
Bagura32rus - Sergeant Major
- Posts: 73
- Joined: Fri Dec 21, 2018 9:37 pm
- Location: RUSSIA
Re: Anti-Recoil Public Release
Update 1.1
FEATURES:
• Undetectable
• Adjustable On-The-Fly Anti-Recoil
• Smart Anti-Recoil
FEATURES:
• Undetectable
• Adjustable On-The-Fly Anti-Recoil
• Smart Anti-Recoil
- Code: Select all
const fix32 verticalCompensation = 5.0;
const fix32 verticalCompensationInc = 0.5;
const fix32 verticalCompensationDec = 0.5;
const fix32 horizontalCompensation = 1.0;
const fix32 verticalRandomMin = 0.0;
const fix32 verticalRandomMax = 2.0;
const fix32 horizontalRandomMin = 0.0;
const fix32 horizontalRandomMax = 2.0;
const fix32 stickNoise = 19.0;
const fix32 splitParameter = 0.3;
const fix32 movementThreshold = 0.9;
fix32 scaleFactor;
main {
if (get_actual(BUTTON_8) && event_active(BUTTON_10)) verticalCompensation += verticalCompensationInc;
if (get_actual(BUTTON_8) && event_active(BUTTON_11)) verticalCompensation -= verticalCompensationDec;
if (is_active(BUTTON_5) && is_active(BUTTON_8)) {
fix32 stick_x = get_val(STICK_1_X);
fix32 stick_y = get_val(STICK_1_Y);
fix32 stick_dist = sqrt(sq(stick_x) + sq(stick_y));
if (stick_dist < splitParameter) {
set_val(STICK_1_X, stick_x);
set_val(STICK_1_Y, stick_y);
} else if (stick_dist < movementThreshold) {
AntiRecoil(STICK_1_Y, STICK_1_X, verticalCompensation, horizontalCompensation);
fix32 stick1_x = get_actual(STICK_1_X);
fix32 stick1_y = get_actual(STICK_1_Y);
fix32 stick2_x = get_actual(STICK_2_X);
fix32 stick2_y = get_actual(STICK_2_Y);
set_val(STICK_1_X, abs(stick1_x) < stickNoise ? 0.0 : get_val(STICK_1_X));
set_val(STICK_1_Y, abs(stick1_y) < stickNoise ? 0.0 : get_val(STICK_1_Y));
set_val(STICK_2_X, abs(stick2_x) < stickNoise ? 0.0 : get_val(STICK_2_X));
set_val(STICK_2_Y, abs(stick2_y) < stickNoise ? 0.0 : get_val(STICK_2_Y));
}
}
}
void AntiRecoil(uint8 axisY, uint8 axisX, fix32 recoil_Y, fix32 recoil_X)
{
fix32 randomFactorRY = frand(verticalRandomMin, verticalRandomMax);
fix32 randomFactorRX = frand(horizontalRandomMin, horizontalRandomMax);
recoil_Y += randomFactorRY;
recoil_X += randomFactorRX;
if (recoil_Y + recoil_X)
{
fix32 RY = get_actual(axisY);
fix32 RX = get_actual(axisX);
fix32 RXRY = sq(RY) + sq(RX);
if (RXRY <= sq(stickNoise))
{
scaleFactor = sqrt(sq(recoil_Y) + sq(recoil_X));
set_val(axisY, (recoil_Y / scaleFactor) * (scaleFactor + stickNoise));
set_val(axisX, (recoil_X / scaleFactor) * (scaleFactor + stickNoise));
}
else
{
fix32 true_radius = min(sqrt(RXRY), 100.0);
scaleFactor = 100.0 - stickNoise;
RY *= ((true_radius - stickNoise) / true_radius);
RX *= ((true_radius - stickNoise) / true_radius);
recoil_Y -= ((recoil_Y * 0.80) / scaleFactor) * true_radius;
recoil_X -= ((recoil_X * 0.80) / scaleFactor) * true_radius;
RY += recoil_Y - ((recoil_Y / scaleFactor) * abs(RY));
RX += recoil_X - ((recoil_X / scaleFactor) * abs(RX));
scaleFactor = sqrt(sq(RY) + sq(RX));
RY = (RY / scaleFactor) * (scaleFactor + stickNoise);
RX = (RX / scaleFactor) * (scaleFactor + stickNoise);
set_val(axisY, clamp(RY, -100f, 100f));
set_val(axisX, clamp(RX, -100f, 100f));
}
}
return;
}
fix32 frand(fix32 vmin, fix32 vmax) {
return (rand() * (vmax - vmin) + vmin);
}
- Attachments
-
_AntiRecoil_PR.gpc
- (3.29 KiB) Downloaded 4 times
-
turmoil_manpower - Sergeant
- Posts: 7
- Joined: Sat May 06, 2023 7:41 pm
Re: Anti-Recoil Public Release
//const fix32 verticalCompensationInc = 0.5;
//const fix32 verticalCompensationDec = 0.5;
if (get_actual(BUTTON_8) && event_active(BUTTON_10)) verticalCompensation += 0.5;
if (get_actual(BUTTON_8) && event_active(BUTTON_11)) verticalCompensation -= 0.5;
save you a few bytes, but over all very nice work
//const fix32 verticalCompensationDec = 0.5;
if (get_actual(BUTTON_8) && event_active(BUTTON_10)) verticalCompensation += 0.5;
if (get_actual(BUTTON_8) && event_active(BUTTON_11)) verticalCompensation -= 0.5;
save you a few bytes, but over all very nice work
-
MrBrgv - Staff Sergeant
- Posts: 11
- Joined: Sun Dec 27, 2020 9:32 pm
Re: Anti-Recoil Public Release
Hi MrBrgv, I initially had the script written that way, but I made a change to use a constant instead so that people can modify the script more easily. However, I have reverted the change in the newest update since it will save some bytes.
-
turmoil_manpower - Sergeant
- Posts: 7
- Joined: Sat May 06, 2023 7:41 pm
5 posts
• Page 1 of 1
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 48 guests