Page 1 of 1

Double forward push L-stick condition help please

PostPosted: Wed Apr 07, 2021 11:33 am
by Sparky101
Double forward-push L-stick condition help please

I'm trying to write an autowalk function when the Left Stick is pushed forwards twice in a row a short time apart, but I'm having trouble with writing the condition.

tia :)

Re: Double forward push L-stick condition help please

PostPosted: Wed Apr 07, 2021 9:35 pm
by Mad

Re: Double forward push L-stick condition help please

PostPosted: Thu Apr 08, 2021 9:20 am
by Sparky101
Thanks, but although this 'kinda' works it will create issues that make it unusable, perhaps because it was written mainly for buttons and not sticks. Please let me explain...

The problem:

I used this code to do some testing (for full code goto end of post):

Code: Select all
    if(event_active(PS4_LY) && time_release(PS4_LY) < 400)  {
        auto_walk = 1;
    }
 


The main problem with this is that a double-push of the Left Stick in *any* direction with *any* distance (i.e. how far one pushes the stick from centre to the edge) will trigger the autowalk.

List of example issues:
    Push left stick Forwards and then Backwards: this triggers the autowalk.
    Push left stick Left and then Right: this triggers the autowalk.
    Push left stick Left and then Forwards: this triggers the autowalk.
    Do *any* of the above with distance (from centre of the stick) of as little as say 20%: this triggers the autowalk.

And in a combat game like Ghost of Tsushima, heavily using left stick in combat will trigger the auto-walk regularly and so just won't work.


The solution?

Thinking more on the requirements, a good solution would work with the following definition:

"Pushing the Left Stick forwards" means:
    a) Pushing the Left Stick forwards give or take, say, 40 degress from 0 degress (i.e. the top of the stick, or 'due North').
    b) Pushing the Left Stick forwards at least, say, 80% distance from centre of Stick resting place, to the outer edge of the stick range.
    c) Optionally, it would be nice to be able to tweak the following:
    ------- "40 degress from 0 degress"
    ------- "80% distance from centre of Stick resting place"

Also, the left stick should return to within, say, <= 5% of the centre point between pushing the left stick forwards twice to enable the condition to trigger.


I'm not sure if this is possible, but I would find it useful.



This is the full code I have currently:


Code: Select all
// ================================================================
// Ghost of Tsushima - autowalk v1.2
// ================================================================
//
// Autorun
// ========
// To start: press L3 whist running (whilst Left Stick is forwards)
// To stop: press Circle OR Left Stick down
//
// Auto-walk
// ========
// To start: Push L Stick forwards twice
// To stop: press Circle OR Left Stick down
//
 
#pragma METAINFO("", 1, 0, "Tsushima_Autowalk")
#include <ps4.gph>
bool auto_run;   
bool auto_walk;
main {
 
    ///////////////////////////////////////////////////////////////
    // detect ON input
    ///////////////////////////////////////////////////////////////
    if(is_active(PS4_LY) && is_active(PS4_L3)) {
        auto_run = 1;
    }
 
 
    if(event_active(PS4_LY) && time_release(PS4_LY) < 400)  {
        // INTENTION: if double push L3 forwards >=80% then autowalk
        auto_walk = 1;
    }
 
    if(is_active(PS4_L3)) {
        // If L3 pressed, disable Cross button
        set_val(PS4_CROSS ,0);
 
        // and iff Cross pressed, enable autowalk
        if(is_active(PS4_CROSS)) {auto_walk = 1;}
    }
 
    if(is_active(PS4_RIGHT)) {
        auto_walk = 1;
    }
 
    ///////////////////////////////////////////////////////////////
    // set output
    ///////////////////////////////////////////////////////////////
    if(auto_run) set_val(PS4_LY, -100);
 
    if(auto_walk) set_val(PS4_LY, -100);   
 
 
    ///////////////////////////////////////////////////////////////
    // detect OFF input
    ///////////////////////////////////////////////////////////////
    if(is_active(PS4_CIRCLE)) {
        auto_run = 0;
        auto_walk = 0;
    }
 
    if(get_actual(PS4_LY) >= 85f) {
        auto_run = 0;
        auto_walk = 0;
    }
 
 
}




tia for any help :)

Re: Double forward push L-stick condition help please

PostPosted: Fri Apr 16, 2021 9:50 am
by Sparky101
Update: I'm working on this script and have realised I need to do the following.

// Left stick Y - if following happen consecutively within .75 secs then activate auto walk
>-90
<-20
>-90

Before I can implement this, I need help on this thread "Problem using ":
viewtopic.php?f=26&t=18067

Re: Double forward push L-stick condition help please

PostPosted: Sat Apr 17, 2021 11:28 am
by Sparky101
I've done it!

Here is the code in case anyone wants to use.

Personally, I intend to merge this with another script so that I can have autorun AND autowalk (for ghost of tsushima)...
- "double L stick forwards" will trigger autowalk
- L3 and L stick forwards will trigger autorun

Code: Select all
// ================================================================
// double_forwards_Lstick_1.0
// ================================================================
//
// autowalk
// ========
// To start: move Lstick forwards twice quickly (allowing Lstick to centre briefly between).
//                     ... feel free to tweak wait1 and wait2 constants if not responsive enough
// To stop: press Circle OR Left Stick down
//
 
 
#pragma METAINFO("", 1, 0, "double_forwards_Lstick_1.0")
#include <ps4.gph>
 
bool auto_walk;
uint32 t_last_forwards; // time L stick last pushed forwards (beyond threshhold)
uint32 t_last_centred;     // time L stick last centred (within threshhold)
uint32 t_XXX;             // time L stick FIRST detected forwards AND then backwards (within threshold)
uint32 wait1 = 250; // allow up to 250ms between t_last_forwards and t_last_centred events, else reset condition
uint32 wait2 = 250; // allow up to 250ms between t_last_centred and t3 events, else reset condition
fix32 Lstick_upper_limit = -90.0;
fix32 Lstick_lower_limit = -10.0;
main {
 
 
    // detect t_XXX (double Lstick forwards)
    if (system_time() - t_XXX < wait2) { // if forwards and backwards within wait2
 
        // if forwards for 2nd time
        if((PS4_LY) <= Lstick_upper_limit) {   
            auto_walk = 1;
        }
    }
 
    else {
 
        // maintain t_last_forwards
        if((PS4_LY) <= Lstick_upper_limit) {   
 
            // update t_last_forwards
            t_last_forwards=system_time(); // t_last_forwards : last time pushed stick forwards beyond upper limit of 90%
 
        }
 
        // maintain t_last_centred and detect t_XXX
        if((PS4_LY) >= Lstick_lower_limit) {   
            t_last_centred = system_time(); // t_last_centred : last time centred Left stick within lower limit of 10%
 
            if (t_last_centred - t_last_forwards < wait1) { // and within wait1 time limit
                t_XXX = system_time();
            }
        }
    }
 
 
    if(auto_walk) set_val(PS4_LY, -100);
 
 
    if(is_active(PS4_CIRCLE)) {
        auto_walk = 0;
    }
 
    if(get_actual(PS4_LY) >= 85f) {
        auto_walk = 0;
    }
 
 
 
}
 
 
 
 
 


# autorun autowalk double push quick quickly double tap forwards Lstick Left stick old school generic