wasiejen / Free-Snap-Tap

A Python-based Snap Tap program with adjustable Tap Groupings, Rebinds (Key Replacements), Macros (Aliases) and per key adjustable delay to imitate natural input
GNU General Public License v3.0
32 stars 5 forks source link

Is it possible to make a counter-strafe? #32

Closed guikaua12 closed 1 week ago

guikaua12 commented 3 weeks ago

I was wondering if it is possible to make a counter-strafe, i've tried this but could not make it work:

# when release a, tap d to do a counter-strafe,
+a, -d|10, +d|10
# same with d
+d, -a|10, +a|10

when i release A my character keep walking to the left, same with D but to the right

wasiejen commented 3 weeks ago

It behaves like intented :-D

+a is the trigger and will be replaced by -d|10, +d|10, so key a is still pressed.

try:

+a, +a|10, -d|10|10, +d|0|0  # -> when +a, +a pressed, delay 2-10 ms, -d, delay 10 ms, +d, no delay
+d, +d|10, -a|10|10, +a|0|0

|0|0 means without any delay (min delay = 0 and max delay = 0)

It can interfere with the real input on a and d - right now working on something to always prioritize real input in case of clashing simulated input from aliases.

wasiejen commented 2 weeks ago

Should now work in V0.8.5 without interference from aliases.

try out:

+w, +w|5|2, -s|25|15, +s|0|0   #stop_forward
+s, +s|5|2, -w|25|15, +w|0|0   #stop_back
+a, +a|5|2, -d|25|15, +d|0|0   #stop_left
+d, +d|5|2, -a|25|15, +a|0|0   #stop_right

Works really amazing in CS2 for me. :-)

s0cr4tes commented 2 weeks ago

How do I get to test the new counter strafe aliases, where do I add the aliases mentioned in the example from 0.8.5? I tried adding the code into both key- and tap_group.txt but I cant get it to work as intended.

The original snap-tap still works.

FYI there is also a little errormsg in the new release even without doing any changes to the tap- or keys groups. 11

wasiejen commented 2 weeks ago

Moin Moin.

That error is a start for a implementation of state tracking for all pressed keys to be able to use key combinations as triggers. Does nothing yet except write out this debug stuff - forgot to set it to only show when debugging.

The above mentioned stop_movements need to be in the key_group file, not he tap_group file. Then they should be recognized and shown in the menu under key_groups.

Tested the functionality in cs2 until it worked like intended. :-) Felt like it created some new knots in my brain while debugging this little beast. xD

And sry for the late answer. Did not see it yesterday - was just on the lookout for new issues, but no new ones arrived. xD

s0cr4tes commented 2 weeks ago

Hi, thanks for the response. I might have misunderstood the code addition.

I initially thought it would function like an autostop, similar to what's shown in this video: https://www.youtube.com/watch?v=PKAU70vWce0&t=30s. I believe this is what guikaua12 was referring to.

I followed your instructions and added the code as suggested:

2024-08-30 09_08_29-Window

The snap-tap functionality is working as it did before. I just thought the new addition was something different :)

Great work, and keep it up! :)

wasiejen commented 2 weeks ago

I had a look at the video (script down below) and my goal was to create something similar in function. But I must confess I am not entirely sure what the difference is to my approach. My script as seen above just presses the opposite key shortly when a key is released, And that for all movement keys. My experience while playing cs2 with it are really good - just had to increase the delays a bit to not get kicked (now using +w, +w|12|4, -s|40|25, +s|0|0). :-)

Can someone explain exactly to me what that does? Why is there a "rightleft 0 1 0"? What does "!forwardback 0 1 0"? And why the hell "!forwardback 0.00000000000001 0 0"? xD

If I understand it I can try to replicate it. :-)

alias "+autostop_forward" "+forward; rightleft 0 1 0; !forwardback 0 1 0"
alias "-autostop_forward" "-forward; !forwardback 0.00000000000001 0 0"
alias "+autostop_back" "+back; rightleft 0 1 0; forwardback 0 1 0"
alias "-autostop_back" "-back; forwardback 0.00000000000001 0 0"
alias "+autostop_left" "+left; forwardback 0 1 0; rightleft 0 1 0"
alias "-autostop_left" "-left; rightleft 0.00000000000001 0 0"
alias "+autostop_right" "+right; forwardback 0 1 0; !rightleft 0 1 0"
alias "-autostop_right" "-right; !rightleft 0.00000000000001 0 0"

bind "w" "+autostop_forward"
bind "s" "+autostop_back"
bind "a" "+autostop_left"
bind "d" "+autostop_right"
s0cr4tes commented 2 weeks ago

I believe this might be a concept from the era when joysticks were considered viable, and that the 'forwardback' and 'leftright' functions are remnants of that time.

The best explanation I’ve come across starts at 0:50 in this video: https://www.youtube.com/watch?v=Q9cTcKg-nVM&t=1s.

I tried using your code, but I’m not getting the instant stop when I release the 'a' or 'd' key. If you try running CS2, load the config from the video, and set cl_showpos "1", you’ll see that the velocity almost instantly stops when you release 'a' or 'd', which is different from the normal +right and +left behavior.

I hope this clarifies the issue.

You’re doing great work—the snap-tap feature is functioning perfectly across the board.

wasiejen commented 2 weeks ago

Mh the problem might be that the counter strafe duration is just to short in the script.

When i counter strafe manually and give out the times for the Key presses/releases I get:

# I think good ?
time: 122410734, vk_code: 68 - press   - real
time: 122410968, vk_code: 68 - release - real
time: 122411000, vk_code: 65 - press   - real                32 ms delay to counter tap
time: 122411093, vk_code: 65 - release - real               93 ms long long duration of counter tap

# felt very good
time: 122412250, vk_code: 68 - press   - real
time: 122412718, vk_code: 68 - release - real
time: 122412812, vk_code: 65 - press   - real               100 ms delay
time: 122412890, vk_code: 65 - release - real               80 ms long

# very good
time: 122413484, vk_code: 68 - press   - real
time: 122413859, vk_code: 68 - release - real
time: 122413906, vk_code: 65 - press   - real                  47 ms delay
time: 122414000, vk_code: 65 - release - real                 around 100ms long

so we might have to test out a good timing :-)

edit:

#automatic snap tap when key released
+w, +w|20|10, -s|80|75, +s|0|0
+s, +s|20|10, -w|80|75, +w|0|0
+a, +a|20|10, -d|80|75, +d|0|0
+d, +d|20|10, -a|80|75, +a|0|0

Feels very weird - like glued to the ground. That is even triggering some movement nausea Oo

Some minor overcompensation if max speed was not reached before. Might be needed to measure the time of a real movement press duration and if not over a certain threshold apply a down counter press with scaled down duration. But for that data for acceleration time and optimal counter time are needed to find out how it scales. :-) (maybe it even changes on a per weapon basis and so changes with current max speed???)

wasiejen commented 2 weeks ago

Some more testing revealed that for the different directions different times of counter press duration are needed to stop. I guess it scales with max velocity. Forward is fastest and so needs the longest duration to be negated.

#tap_groups
a, d
w, s

#key_groups
+w, +w|20|10, -s|75|75, +s|0|0
+s, +s|20|10, -w|50|50, +w|0|0
+a, +a|20|10, -d|50|50, +d|0|0
+d, +d|20|10, -a|50|50, +a|0|0

Above settings only compensates around 60% (just a guess) percent in left and right direction - good for wiggling a bit while shooting. Forward 75-80% negation (90-100ms is full negation with m4a4 - but really weird when stopping and turning -> moved backwards because turning seems to transform forward momentum in left/right or even backward momentum (180° turn) [hypothesis - conservation of momentum] )

Tap_groups a,d and w,s must be active to not receive interference from alias/macro activating the opposite keys (tap_groups used to determine what the opposite keys are in the first place).

correction:

All directions need the same time to be negated completely - around 100 ms. Just might have other accelerations?? Movement feels strange with that because the fluidity of movement is lost. And my aim is worse because I expect to move further xD

+w, +w|15|5, -s|100|100, +s|0|0
+s, +s|15|5, -w|100|100, +w|0|0
+a, +a|15|5, -d|100|100, +d|0|0
+d, +d|15|5, -a|100|100, +a|0|0
s0cr4tes commented 2 weeks ago

I've also played around with it and i cant get it to work as well as the autostrafe.cfg from the youtubevideo. It improves, but not quite there.

So i stick with the cfg with the snap-tap as a compliment.

wasiejen commented 1 week ago

I think counter-strafe is as improved as it gets with version 0.9.3 without changing the general approach. :-) It will never work as well as the in-game scripting via config files, because this program does not access any game information. The scripting literally tells the game to walk extremely slowly. (btw. your reference video was extremely helpful to understand that).

The next level would be to observe mouse movement and abort the simple counter strafing if rotated to much or replace counter-strafe keys to fit to the direction of inertia ... and eventually it would result in building a model of the in-game movement behavior/physics. Sounds fun :-O - but in the end it will never be as good as in-game scripting via config files, because there is still no interaction with the game: run into a wall and the program will still think you are at full speed and counter-strafe with that as basis. :-)