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

#1 2013-04-19 20:54:39

Maltese_Falcon
Scratcher
Registered: 2013-03-25
Posts: 100+

Walking animation script

I've been doing a platformer with a walking person (Actually Greek God). He has a series of 5 costumes that he uses when walking.
Here's my script:

When gf clicked
Set [Step v] to [RightFoot] //Make it so that he starts walking with his right foot
forever
if <key [right arrow v] pressed
if <(Step) = [RightFoot]
Point in direction [90 v]
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] secs
Switch to costume [FullRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] Secs
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]
Point in direction [90 v]
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] secs
Switch to costume [FullLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] Secs
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [RightFoot]
end
end
if <key [left arrow v] pressed
if <(Step) = [RightFoot]
Point in direction [-90 v]
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] secs
Switch to costume [FullRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] Secs
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]
Point in direction [90 v]
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] secs
Switch to costume [FullLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] Secs
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [RightFoot]
end
end
end
The problem with this is that when you switch direction in the middle of a step, it has to finish the step it's currently on before switching direction. Any suggestions? Sorry if this is too complicated or if I'm not being very clear.

Offline

 

#2 2013-04-19 21:04:04

Maltese_Falcon
Scratcher
Registered: 2013-03-25
Posts: 100+

Re: Walking animation script

Maltese_Falcon wrote:

I've been doing a platformer with a walking person (Actually Greek God). He has a series of 5 costumes that he uses when walking.
Here's my script:

When gf clicked
Set [Step v] to [RightFoot] //Make it so that he starts walking with his right foot
forever
if <key [right arrow v] pressed>
if <(Step) = [RightFoot]>
Point in direction [90 v]
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] secs
Switch to costume [FullRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] Secs
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]>
Point in direction [90 v]>
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] secs
Switch to costume [FullLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] Secs
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [RightFoot]
end
end
if <key [left arrow v] pressed>
if <(Step) = [RightFoot]>
Point in direction [-90 v]
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] secs
Switch to costume [FullRightStep v]
Wait [0.1] secs
Switch to costume [MiddleRightStep v]
Wait [0.1] Secs
Switch to costume [StartRightStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]>
Point in direction [90 v]
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] secs
Switch to costume [FullLeftStep v]
Wait [0.1] secs
Switch to costume [MiddleLeftStep v]
Wait [0.1] Secs
Switch to costume [StartLeftStep v]
Wait [0.1] secs
Switch to costume [StandingStill]
Set [Step v] to [RightFoot]
end
end
end
The problem with this is that when you switch direction in the middle of a step, it has to finish the step it's currently on before switching direction. Any suggestions? Sorry if this is too complicated or if I'm not being very clear.

I think I fixed it.

Offline

 

#3 2013-04-19 21:10:05

Liamadams
Scratcher
Registered: 2012-12-08
Posts: 100+

Re: Walking animation script

Maltese_Falcon wrote:

Maltese_Falcon wrote:

I've been doing a platformer with a walking person (Actually Greek God). He has a series of 5 costumes that he uses when walking.
Here's my script:

When gf clicked
set [Step v] to [RightFoot] //Make it so that he starts walking with his right foot
forever
if <key [right arrow v] pressed?>
if <(Step) = [RightFoot]>
point in direction [90 v]
switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] secs
switch to costume [FullRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] Secs
switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]>
point in direction [90 v]
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] secs
switch to costume [FullLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] Secs
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [RightFoot]
end
end
if <key [left arrow v] pressed?>
if <(Step) = [RightFoot]>
point in direction [-90 v]
switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] secs
switch to costume [FullRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] Secs
Switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]>
point in direction [90 v]
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] secs
switch to costume [FullLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] Secs
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [RightFoot]
end
end
The problem with this is that when you switch direction in the middle of a step, it has to finish the step it's currently on before switching direction. Any suggestions? Sorry if this is too complicated or if I'm not being very clear.

I think I fixed it.

fixed the scratchblocks.

Last edited by Liamadams (2013-04-20 16:12:48)


http://i39.tinypic.com/3309476.jpg

Offline

 

#4 2013-04-19 21:26:31

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Walking animation script

Liamadams wrote:

Maltese_Falcon wrote:

Maltese_Falcon wrote:

I've been doing a platformer with a walking person (Actually Greek God). He has a series of 5 costumes that he uses when walking.
Here's my script:

When gf clicked
set [Step v] to [RightFoot] //Make it so that he starts walking with his right foot
forever
if <key [right arrow v] pressed?>
if <(Step) = [RightFoot]>
point in direction [90 v]
switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] secs
switch to costume [FullRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] Secs
switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]>
point in direction [90 v]
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] secs
switch to costume [FullLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] Secs
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [RightFoot]
end
end
if <key [left arrow v] pressed?>
if <(Step) = [RightFoot]>
point in direction [-90 v]
switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] secs
switch to costume [FullRightStep v]
wait [0.1] secs
switch to costume [MiddleRightStep v]
wait [0.1] Secs
Switch to costume [StartRightStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [LeftFoot]
end
if <(Step) = [LeftFoot]>
point in direction [90 v]
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] secs
switch to costume [FullLeftStep v]
wait [0.1] secs
switch to costume [MiddleLeftStep v]
wait [0.1] Secs
switch to costume [StartLeftStep v]
wait [0.1] secs
switch to costume [StandingStill v]
set [Step v] to [RightFoot]
end
end
The problem with this is that when you switch direction in the middle of a step, it has to finish the step it's currently on before switching direction. Any suggestions? Sorry if this is too complicated or if I'm not being very clear.

I think I fixed it.

fixed the scratchblocks.

There was an extra end at the end of the forever loop. Anyway, yes, I do have an idea, or ideas, depending on how you look at it. So, somehow you're going to need to change the script so that you can switch directions easily. One method which you shouldn't do is adding in a bunch of if's into your code so that it can exit out easily. For example:

switch to costume [MiddleLeftStep v]
wait (0.1) Secs
if <key [left arrow v] pressed?>
 switch to costume [StartLeftStep v]
 wait (0.1) secs
 if <key [left arrow v] pressed?>
  switch to costume [StartLeftStep v]
  wait (0.1) secs
 end
end

So this works, though there must be some easier method, right? Yes, there is. It involves using these two key blocks:

next costume
switch to costume ((costume #) - (1))

Do you see where I'm heading?

Anyway, I'm going to have to leave the rest as a mystery seeing as I don't have the exact scripts with me right now, and seeing as I have to go.

With regards,

ErnieParke

Last edited by ErnieParke (2013-04-19 21:27:00)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer