Formula for Running Animation

Posted by Mush on May 11, 2008, 3:49 p.m.

I was inpired by Excalibur333's platform example to try to animate a running cycle using GML.

I first used Excalibur333's code as a base for the person's upper leg animation:

//Right upper leg

angle[0] = 270 + (50*(sin(incr[0])))

incr[0]+=0.2

end_x[0] = x + lengthdir_x(50, angle[0] )

end_y[0] = y + lengthdir_y(50, angle[0] )

//Left upper leg

angle[2] = 270 + (50*(sin(incr[2])))

incr[2] -=0.2

end_x[2] = x + lengthdir_x(50, angle[2] )

end_y[2] = y + lengthdir_y(50, angle[2] )

After studying how a human runs and many hours of trial and error, I came up with the lower leg's animation:

//Right lower leg

angle[1] = 310 + (50*(sin(incr[1])))

incr[1]+=(50*(sin(incr[0])))/1000

end_x[1] = end_x[0] + lengthdir_x(50, angle[1] )

end_y[1] = end_y[0] + lengthdir_y(50, angle[1] )

//Left lower leg

angle[3] = 336 + (50*(sin(incr[3])))

incr[3] += (50*(sin(incr[0]*-1))))/1000

end_x[3] = end_x[2] + lengthdir_x(50, angle[3] )

end_y[3] = end_y[2] + lengthdir_y(50, angle[3] )

Feet:

//Right

foot_x[0] = end_x[1] + lengthdir_x(20, angle[1]-130 )

foot_y[0] = end_y[1] + lengthdir_y(20, angle[1]-130 )

//Left

foot_x[1] = end_x[3] + lengthdir_x(20, angle[3]-130 )

foot_y[1] = end_y[3] + lengthdir_y(20, angle[3]-130 )

Draw:

//Right

draw_line_width(x,y,end_x[0],end_y[0],5)

draw_line_width(end_x[0],end_y[0],end_x[1],end_y[1],5)

//Left

draw_line_width(x,y,end_x[2],end_y[2],5)

draw_line_width(end_x[2],end_y[2],end_x[3],end_y[3],5)

/Body Placeholder

draw_line_width(x,y,x-5,y-70,5)

//Feet

draw_line_width(end_x[1],end_y[1],foot_x[0],foot_y[0],10)

draw_line_width(end_x[3],end_y[3],foot_x[1],foot_y[1],10)

_______________________________

I still have to do the arms, body head, etc. I may also try to do a walking animation as well.

Example

Comments

Juju 16 years, 10 months ago

Very nice. The front leg could do with going slightly more vertical though.

Omega_Squid 16 years, 10 months ago

That is pretty cool - looking forward to the entire animation!

Scott_AW 16 years, 10 months ago

With some slight modifications it can even be used for 3d models with multiple parts. I'd check it out but I boycott gm 7 for its immobility.

Excalibur333 16 years, 10 months ago

Sweet. I thought about doing lower legs to but the game I am working on is a simpler style and so I just decided to stick with what I had. Great job. I can't wait to see it finished.

sirxemic 16 years, 10 months ago

You do realize that the body goes up and down while walking, right?

Mush 16 years, 10 months ago

Quote:
still have to do the arms, body head, etc.
Quote:
//Body Placeholder