can anyone tell me how i would incorporate a walking animation in my game? i'm using the x and y velocity things and it's just confused me to no end.
here is my game if you would like to see what i mean, and possibly edit the script for me.
thanks!!
http://scratch.mit.edu/projects/bi0/2721954
Offline
It gets very complicated if you want more animations (e.g. "jumping", "walking", "sprinting", etc.), but the basics:
You should change costumes everytime your x-position changes by a certain amount, not based on time. E.g.
forever set [x_save v] to (x position) wait until <([abs v] of ((x position)-(x_save))) > (step size)> next costumeAdditionally, things like collisions/physics are easier if you have a separate "collision" costume or "collider" sprite, as changing costumes can result in being outside a wall with one costume but inside the wall when you change to the next costume.
Last edited by MoreGamesNow (2012-08-10 09:13:09)
Offline
MoreGamesNow wrote:
It gets very complicated if you want more animations (e.g. "jumping", "walking", "sprinting", etc.), but the basics:
You should change costumes everytime your x-position changes by a certain amount, not based on time. E.g.forever set [x_save v] to (x position) wait until <([abs v] of ((x position)-(x_save))) > (step size)> next costumeAdditionally, things like collisions/physics are easier if you have a separate "collision" costume or "collider" sprite, as changing costumes can result in being outside a wall with one costume but inside the wall when you change to the next costume.
Oh Heck, you bet me too it xD
This is however a better idea than I had, I used extra variables and broadcasts, MoreGamesNow's is more easy
Offline
Step size is basically a variable that stores the size, in pixels, that each frame moves. For example, if each step moves your character 10 pixels and you have 5 costumes, "step size" would be 2 (10/5). This script might make more sense, as you can just fit it into whatever movement-loop-script you have
when gf clicked set [step_x_storage v] to (x position) forever movement stuff if<([abas v] of ((x position)-(step_x_storage))) > (2)> switch to next costume in walking cycle set [step_x_storage v] to (x position) endEdit, this script should be even more compatible (it assumes your walk cycle is a loop starting at costume 1 and going to costume 3).
when gf clicked set [i v] to (0) set [step_x_storage v] to (x position) forever movement stuff if<([abas v] of ((x position)-(step_x_storage))) > (2)> set [i v] to (((i)+(1)) mod (3)) switch to costume ((i)+(1)) set [step_x_storage v] to (x position) end
Last edited by MoreGamesNow (2012-08-10 14:46:00)
Offline
thanks for the update. problem now is that my character uses the jump costume for the walking cycle. also, when he jumps and moves whilst jumping the costumes still change, aaaand when he stops walking he stops on costume b, i want him to stop on a.
Offline