Coding Sword animation swing

J

Joao Cruz Malhao

Guest
Hi, I've been researching (working on an rpg) and found that instead of making hundreds of attack animations would just be easier to animate with code the sword_spr swing. Meaning, just the sword sprite rotating in front of the player's direction during the attack time. How should i approach this, thank you I'm still fairly new to gml. Any tips or help would be much appreciated.
 

Paskaler

Member
Well, for the animation you could define a start angle, an end angle and a speed the sword should rotate at. Once you have these, thr code to rotate would be something like this(assuming the weapon is it's own object, and this is put in the step event):

Code:
if inSwing {
    if image_angle == endAngle {
        inSwing = false; // animation finished
    }
    image_angle += dsin(endAngle - image_angle) * rotateSpeed;
}
Then when you want to swing set inSwing = true, and reset image_angle.
 
J

Joao Cruz Malhao

Guest
Well, for the animation you could define a start angle, an end angle and a speed the sword should rotate at. Once you have these, thr code to rotate would be something like this(assuming the weapon is it's own object, and this is put in the step event):

Code:
if inSwing {
    if image_angle == endAngle {
        inSwing = false; // animation finished
    }
    image_angle += dsin(endAngle - image_angle) * rotateSpeed;
}
Then when you want to swing set inSwing = true, and reset image_angle.
thank you!
 
Top