This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-10 08:53:07

bi0
New Scratcher
Registered: 2012-08-08
Posts: 10

walking animation

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

 

#2 2012-08-10 09:10:02

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: walking animation

I'm looking now  wink


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#3 2012-08-10 09:12:49

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: walking animation

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 costume
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.

Last edited by MoreGamesNow (2012-08-10 09:13:09)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2012-08-10 09:19:09

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: walking animation

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 costume
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.

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  smile


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#5 2012-08-10 09:20:18

bi0
New Scratcher
Registered: 2012-08-08
Posts: 10

Re: walking animation

i don't understand..LOL

Offline

 

#6 2012-08-10 09:29:29

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: walking animation

bi0 wrote:

i don't understand..LOL

lol, basically add the variable and script he used, and it will work  wink


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#7 2012-08-10 09:45:58

bi0
New Scratcher
Registered: 2012-08-08
Posts: 10

Re: walking animation

it still wont work ): does the step size need configuring or something

Offline

 

#8 2012-08-10 10:09:23

daniel_j
Scratcher
Registered: 2012-05-22
Posts: 100+

Re: walking animation

I dont know, I tried that out too, I guess he left that bit up for you  hmm  Sorry.


http://i50.tinypic.com/2dhgnsx.jpg

Offline

 

#9 2012-08-10 10:18:29

bi0
New Scratcher
Registered: 2012-08-08
Posts: 10

Re: walking animation

ugh lol. what was your idea? i'd like to try this out.

Offline

 

#10 2012-08-10 14:42:26

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: walking animation

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)
end
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).

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)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#11 2012-08-10 16:47:21

bi0
New Scratcher
Registered: 2012-08-08
Posts: 10

Re: walking animation

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

 

Board footer