Rotate Analog Combo

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

Rotate Analog Combo

Postby creedkiller » Tue Jan 16, 2018 3:13 am

Need help creating a combo which would rotate a analog stick either clockwise or anti-clockwise using a math formula with the ability to set the time/speed of a complete (360 degree) rotation. Attached is a gif of joy.cpl (Game Controller Properties in windows) showing a controller making the action I would like to create.

rotation.gif
rotation.gif (14.56 KiB) Viewed 875 times


EDIT1, rather than a combo, i think it would be better as a function
Last edited by creedkiller on Tue Jan 16, 2018 4:13 am, edited 1 time in total.
creedkiller
Lieutenant
Lieutenant
 
Posts: 293
Joined: Fri Mar 17, 2017 4:08 pm

Re: Rotate Analog Combo

Postby bonefisher » Tue Jan 16, 2018 3:24 am

Here on both sticks change in define section how fast, big or steps:

Code: Select all
 
#define CIRCLE_RADIUS_R       40.0
#define CIRCLE_RADIUS_L       40.0
#define CIRCLE_STEP_R         .01
#define CIRCLE_STEP_L         .01
#define CIRCLE_SPEED_R        20
#define CIRCLE_SPEED_L        20
 
bool ON_OFF_R;
bool ON_OFF_L;
 
int AIM_ASSISTS;
 
fix32 angle_R;
fix32 angle_L;
 
main {
    // double tap toggle on/off
    if(event_active(BUTTON_2) && time_release(BUTTON_2) < 140) {
        AIM_ASSISTS = !AIM_ASSISTS;
    }
    if(AIM_ASSISTS) {
    if(ON_OFF_R == 1) {
         set_val(STICK_1_X, CIRCLE_RADIUS_R * cos(angle_R));
         set_val(STICK_1_Y, CIRCLE_RADIUS_R * sin(angle_R));
            combo_run(AutoCircle_R);
    }
 
      if(get_actual(STICK_1_Y) < -35.0 || get_actual(STICK_1_Y) > 35.0 ||
       get_actual(STICK_1_X) < -35.0 || get_actual(STICK_1_X) > 35.0) {
        combo_stop(AutoCircle_R);
        ON_OFF_R = 0;
    }else {
        ON_OFF_R = 1;
    }
    if(ON_OFF_L == 1) {
         set_val(STICK_2_X, CIRCLE_RADIUS_L * cos(angle_L));
         set_val(STICK_2_Y, CIRCLE_RADIUS_L * sin(angle_L));
            combo_run(AutoCircle_L);
    }
 
      if(get_actual(STICK_2_Y) < -35.0 || get_actual(STICK_2_Y) > 35.0 ||
       get_actual(STICK_2_X) < -35.0 || get_actual(STICK_2_X) > 35.0) {
        combo_stop(AutoCircle_L);
        ON_OFF_L = 0;
    }else {
        ON_OFF_L = 1;
    }
      }
}
 
combo AutoCircle_R {
    wait(CIRCLE_SPEED_R);
    angle_R = mod(angle_R + CIRCLE_STEP_R, 2.0 * PI);
}
 
combo AutoCircle_L {
    wait(CIRCLE_SPEED_L);
    angle_L = mod(angle_L + CIRCLE_STEP_L, 2.0 * PI);
}
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Rotate Analog Combo

Postby creedkiller » Tue Jan 16, 2018 4:15 am

bonefisher wrote:Here on both sticks change in define section how fast, big or steps:

thanks for that quick reply bonefisher. :smile0517:

EDIT 1. Really elegant code, thanks again, exactly what I need.
creedkiller
Lieutenant
Lieutenant
 
Posts: 293
Joined: Fri Mar 17, 2017 4:08 pm

Re: Rotate Analog Combo

Postby bonefisher » Tue Jan 16, 2018 4:43 am

:smile0517:
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 125 guests

cron