GML MADE A SWORD SWING SCRIPT

zghaun

Member
Hello Everyone! I made a swing animation for Melee Attacks BUT it isn't very versatile when it comes to changing direction, I am currently having a hard time making it versatile

CREATE VARIABLES
GML:
melee_state = 0;//Counter Current Anim Number
melee_timer = 0;//Animation Timers
melee_anims = 3;//Number of Positions

melee_angle[0] = 315;
melee_pos[0] = 30;//Distance of Handle
melee_dir[0] = 315;//Direction of weapon
melee_time[0] = 40;//Steps Between Animations
melee_turn[0] = 1;//1 = Clockwise -1 = Turn Counter Clockwise

melee_angle[1] = 120;
melee_pos[1] = 60;//Distance of Handle
melee_dir[1] = 120;//Direction of weapon
melee_time[1] = 10;
melee_turn[1] = -1;//1 = Clockwise -1 = Turn Counter Clockwise, Turn Direction when Moving Toward this Direction

melee_angle[2] = 60;
melee_pos[2] = 70;//Distance of Handle
melee_dir[2] = 450;//Direction of weapon
melee_time[2] = 10;//Distance of Handle
melee_turn[2] = 1;//1 = Clockwise -1 = Turn Counter Clockwise

melee_angle[3] = 0;
melee_pos[3] = 90;//Distance of Handle
melee_dir[3] = 0;//Direction of weapon
melee_time[3] = 60;//Distance of Handle
melee_turn[3] = 1;//1 = Clockwise -1 = Turn Counter Clockwise
x1 = lengthdir_x(melee_pos[0],melee_angle[0]);
y1 = lengthdir_y(melee_pos[0],melee_angle[0]);
//Sum Variables
anim_dir = 0;
xx1 = 0;
yy1 = 0;
xx2 = 0;
yy2 = 0;
pdr = 0;
pds = 0;
r = 0;
das = 0;
dal = 0;
fn_a = 0;
STEP
GML:
melee_timer += 1;
for(m=0;m<=melee_anims;m++)
{
    if melee_state = m
    {
    var mm = m + 1;
    if m = melee_anims
    {
        mm = 0;
    }
    xx1 = lengthdir_x(melee_pos[m],melee_angle[m]);
    yy1 = lengthdir_y(melee_pos[m],melee_angle[m]);
    xx2 = lengthdir_x(melee_pos[mm],melee_angle[mm]);
    yy2 = lengthdir_y(melee_pos[mm],melee_angle[mm]);
    das = angle_difference(melee_dir[m],melee_dir[mm]);
    dal = (360 - abs(das)) * sign(das);
    if melee_turn[mm] = sign(das)
            {fn_a = -das;}
            else
            {fn_a = dal;}
    var mfa = (melee_timer/melee_time[melee_state]) * fn_a;
    if melee_timer > melee_time[m]
    {
        melee_timer = 0;
        melee_state += 1;
        if melee_state > melee_anims
        {
        melee_state = 0;
        xx1 = lengthdir_x(melee_pos[0],melee_angle[0]);
        yy1 = lengthdir_y(melee_pos[0],melee_angle[0]);
        xx2 = lengthdir_x(melee_pos[1],melee_angle[1]);
        yy2 = lengthdir_y(melee_pos[1],melee_angle[1]);
        }
    }
    pdr = point_direction(xx1,yy1,xx2,yy2);
    pds = point_distance(xx1,yy1,xx2,yy2);
    r = (melee_timer/melee_time[melee_state]) * pds;
    anim_dir = melee_dir[m] + mfa;
    }
}
    x1 = xx1 + lengthdir_x(r,pdr);
    y1 = yy1 + lengthdir_y(r,pdr);
DRAW
GML:
draw_sprite_ext(sprite_index,
                0,
                x+x1,
                y+y1,
                image_xscale,
                image_yscale,
                image_angle + anim_dir,
                c_white,
                image_alpha);
 

Gamebot

Member
If all your doing is trying to "flip" your sprite give your image_xscale a negative number. Generally:

1 = right
- 1 = left

Otherwise what do mean not versatile? What are you needing it do that it doesn't?
 

zghaun

Member
If all your doing is trying to "flip" your sprite give your image_xscale a negative number. Generally:

1 = right
- 1 = left

Otherwise what do mean not versatile? What are you needing it do that it doesn't?
Flipping it would only affect the sprite not the angles and direction the sprite is moving or turning,
I'm trying to figure out how to also flip the movement and turning of the animation while relative to mouse direction
 
Top