"Dynamic Recoil" (Fully Automatic Anti-Recoil Compensation)
Posted: Wed Apr 17, 2019 3:34 am
"Dynamic Recoil"
Okay folks here it is. Dynamic Recoil / fully automatic anti-recoil compensation!!! I asked around and could not find any examples. So, with some help from “@don’t at me” and "@Buffy" I have come up with a method of automatically adjusting your recoil. Basically, it will auto adjust your vertical recoil each time you move your right thumb stick while firing your weapon. This method should produce better results the more you use a weapon. Its great for multiplayer matches where you use the same weapon. For other game modes like battle royal it should produce a medium between multiple weapons. Eventually I will most likely add the ability to store and switch the recoil value when you hit the button to switch weapons or lock the value all together. For now, there are two ways you can use this. Just keep it on and it should always try to compensate and improve. Or go to a range, then after you have a weapon dialed in, annotate the output value to use in other manual anti-recoil scripts. Such as this one:
https://www.consoletuner.com/forum/viewtopic.php?f=23&t=12205&wpureload=1
This code will most likely be incorporated as an option in that script anyway. The new anti recoil compensation value is output to the Gtuner output window every time you release the trigger. Just squeezing the trigger will not alter the value so long as your stick noise does not exceed 8. If it does just change that variable in the code and consider getting a new controller.
Technically speaking, while the trigger is depressed it records the position of your right thumb stick every 50 milliseconds. Then every time your thumb stick goes back to a neutral position or is released, it sums and averages the last 100 positions and modifies your vertical anti-recoil based on that average. For now the result is not persistent so if you switch slots or reload the script it will reset. There is a balance between usage time and amount of information captured which leads to accuracy. With that being said I slowed down the rate of compensation for more constant accuracy. Meaning it will take you longer to get it dialed in but once its there it should stay pretty consistent. So please go test this on a wall somewhere before jumping into a match. If you notice some crazy forces just try to compensate or reset the script. This hasn't happened to me yet but I have only tested it today and there is definitely room for improvement. This is a beta so it will most likely change. If you use this code please consider leaving feedback so we can continue to improve. To drag and drop just search for “Dynamic Recoil” in the online resources of Gtuner.
Thanks
Licensing/Usage:
Open source code.
Still in beta and unoptimized.
Free to use and modify.
Please DO NOT distribute for profit.
If you use this code please credit:
@User101 - for concept and creation of "Dynamic Recoil"
@Don't at me - for syntax contributions
@Buffy - for syntax contributions
Okay folks here it is. Dynamic Recoil / fully automatic anti-recoil compensation!!! I asked around and could not find any examples. So, with some help from “@don’t at me” and "@Buffy" I have come up with a method of automatically adjusting your recoil. Basically, it will auto adjust your vertical recoil each time you move your right thumb stick while firing your weapon. This method should produce better results the more you use a weapon. Its great for multiplayer matches where you use the same weapon. For other game modes like battle royal it should produce a medium between multiple weapons. Eventually I will most likely add the ability to store and switch the recoil value when you hit the button to switch weapons or lock the value all together. For now, there are two ways you can use this. Just keep it on and it should always try to compensate and improve. Or go to a range, then after you have a weapon dialed in, annotate the output value to use in other manual anti-recoil scripts. Such as this one:
https://www.consoletuner.com/forum/viewtopic.php?f=23&t=12205&wpureload=1
This code will most likely be incorporated as an option in that script anyway. The new anti recoil compensation value is output to the Gtuner output window every time you release the trigger. Just squeezing the trigger will not alter the value so long as your stick noise does not exceed 8. If it does just change that variable in the code and consider getting a new controller.
Technically speaking, while the trigger is depressed it records the position of your right thumb stick every 50 milliseconds. Then every time your thumb stick goes back to a neutral position or is released, it sums and averages the last 100 positions and modifies your vertical anti-recoil based on that average. For now the result is not persistent so if you switch slots or reload the script it will reset. There is a balance between usage time and amount of information captured which leads to accuracy. With that being said I slowed down the rate of compensation for more constant accuracy. Meaning it will take you longer to get it dialed in but once its there it should stay pretty consistent. So please go test this on a wall somewhere before jumping into a match. If you notice some crazy forces just try to compensate or reset the script. This hasn't happened to me yet but I have only tested it today and there is definitely room for improvement. This is a beta so it will most likely change. If you use this code please consider leaving feedback so we can continue to improve. To drag and drop just search for “Dynamic Recoil” in the online resources of Gtuner.
Thanks
Licensing/Usage:
Open source code.
Still in beta and unoptimized.
Free to use and modify.
Please DO NOT distribute for profit.
If you use this code please credit:
@User101 - for concept and creation of "Dynamic Recoil"
@Don't at me - for syntax contributions
@Buffy - for syntax contributions
- Code: Select all
#pragma METAINFO("Dynamic Recoil", 1, 0, "USER101")
#define float fix32
bool Modify = FALSE;
bool run = FALSE;
bool brun = FALSE;
uint8 timer = 0;
uint16 Modifier;
float AntiRecoilVertical;
float AntiRecoilVerticalOld;
float ModifierSum;
float RecoilModifier[100];
float StickNoise = 8.0;
float MinARecoilPercent = 0.0;
init{
pmem_load();
pmem_read(0, &AntiRecoilVertical);
printf("%f", abs(AntiRecoilVertical));
AntiRecoilVerticalOld = AntiRecoilVertical;
}
main {
if (get_val(STICK_2_Y) < -90.0) run = TRUE;
if (!brun && run){
combo_run(Sprint);
brun = TRUE;
}
if (get_val(STICK_2_Y) >= -90.0) brun = FALSE;
if (get_actual(BUTTON_5)){
if (abs(get_actual(STICK_1_X)) < StickNoise) set_val(STICK_1_X, 0.0);
if (abs(get_actual(STICK_1_Y)) < StickNoise) set_val(STICK_1_Y, 0.0);
if (abs(get_actual(STICK_2_X)) < StickNoise) set_val(STICK_2_X, 0.0);
if (abs(get_actual(STICK_2_Y)) < StickNoise) set_val(STICK_2_Y, 0.0);
if (get_val(BUTTON_5)){
AntiRecoil(STICK_1_Y, AntiRecoilVertical);
}
}
/****************************START DYNAMIC RECOIL CODE***********************************
Open source code.
Still in beta and unoptimized.
Free to use and modify.
Please DO NOT distribute for profit.
If you use this code please credit:
@User101 - for concept and creation of "Dynamic Recoil"
@Don't at me - for syntax contributions
@Buffy - for syntax contributions
*****************************************************************************************/
if(is_active(BUTTON_5)){
if(elapsed_time()){
++timer;
if(timer==50){
++Modifier;
if(Modifier > 50) Modifier = 0;
if(abs(get_actual(STICK_1_Y)) >= StickNoise) RecoilModifier[Modifier] = (get_actual(STICK_1_Y));
// printf("<b>RecoilModifier = %f", RecoilModifier[Modifier]);
timer = 0;
}
}
}
if(event_release(STICK_1_Y))Modify = TRUE;
if(Modify && is_active(BUTTON_5)){
uint8 i;
for(i=0; i<100; i++){
ModifierSum += RecoilModifier[i];
RecoilModifier[i] = 0.0;
}
ModifierSum = ModifierSum / 100.0;
// printf("<b>ModifierSum = %f", ModifierSum);
AntiRecoilVertical += ModifierSum;
printf("<b>Anti Recoil Value = %f", AntiRecoilVertical);
Modifier = 0;
ModifierSum = 0.00;
memset(&RecoilModifier, (uint8)0.00, sizeof(RecoilModifier));
Modify = FALSE;
}
if(event_release(BUTTON_5))printf("<b>Anti Recoil Value = %f", AntiRecoilVertical);
/******************************END DYNAMIC RECOIL CODE************************************/
//Save changes to AntiRecoilVertical on weapon switch (STILL TESTING DO NOT USE AUTO SAVE ON MICRO SD SLOT) writes alot
// if(event_active(BUTTON_14) && AntiRecoilVerticalOld != AntiRecoilVertical) {
// pmem_write(0, AntiRecoilVertical);
// pmem_save();
// AntiRecoilVerticalOld = AntiRecoilVertical;
// }
}
combo Sprint {
wait(40);
set_val(BUTTON_9,100);
wait(40);
set_val(BUTTON_9,0);
wait(0);
run = FALSE;
}
/*****************Recoil function provided by Bonefisher and AryanX***********************/
void AntiRecoil(uint8 AxisToApply, float ARecoilToApply)
{
float CurrentX = get_val(STICK_1_X);
float CurrentY = get_val(STICK_1_Y);
float MinARecoilFactor = MinARecoilPercent / 100.0;
float MinARecoilToApply = MinARecoilFactor * ARecoilToApply;
float MovementARecoilToApply = (1.0 - MinARecoilFactor) * ((ARecoilToApply * (100.0 - sqrt(CurrentX*CurrentX + CurrentY*CurrentY))) / (100.0 + abs(CurrentX) + (CurrentY*CurrentY*0.5)));
set_val(AxisToApply,clamp(MinARecoilToApply + MovementARecoilToApply + get_val(AxisToApply),-100.00,100.00 - MinARecoilToApply));
}