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.
Additionally, 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.foreversetx_save ▼tox positionwait until>abs ▼ofx position-x_savestep sizenext 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.Additionally, 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.foreversetx_save ▼tox positionwait until>abs ▼ofx position-x_savestep sizenext 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
Edit, this script should be even more compatible (it assumes your walk cycle is a loop starting at costume 1 and going to costume 3).whenclicked
setstep_x_storage ▼tox positionforevermovement stuffif>abas ▼ofx position-step_x_storage2switch to next costume in walking cyclesetstep_x_storage ▼tox position
whenclicked
seti ▼to0setstep_x_storage ▼tox positionforevermovement stuffif>abas ▼ofx position-step_x_storage2seti ▼tomodi+13switch to costumei+1setstep_x_storage ▼tox position
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