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

#1 2011-10-21 15:43:38

Berserkbw
Scratcher
Registered: 2011-06-07
Posts: 17

Rotate and Walk

In a project I'm currently making, I have made it so the left and right arrow keys rotate the player, but I need to make it so the sprite will walk in the direction it is directed at. Any way how to do that?

Offline

 

#2 2011-10-21 18:27:35

schnrfl
Scratcher
Registered: 2011-10-11
Posts: 500+

Re: Rotate and Walk

The move () steps block makes it walk in its direction.


opposable thumbs • ubc • dvorak • help
sprach eˣius//Foresson

Offline

 

#3 2011-10-22 00:44:27

Fordark
Scratcher
Registered: 2010-08-02
Posts: 100+

Re: Rotate and Walk

schnrfl wrote:

The move () steps block makes it walk in its direction.

You can also use

Code:

[if (direction) = {right (which is usually 90}]
[change x by {positive number}]
[if {direction= = {left (which is usually -90)}]
[change x by {negative number}]

You can also replace the direction with costumes that face right and left, respectively. If you are making the player so actions such as fight, you have to make left and right versions of every action.

Code:

[if (costume) = {number of costume}]

http://dl.dropbox.com/u/34855482/Fordarksig.png

Offline

 

#4 2011-10-22 09:59:53

astroLoger
New Scratcher
Registered: 2011-10-16
Posts: 100+

Re: Rotate and Walk

I am currently developing a platformer called DRAINED and this was how I did it:

I created a variable called Rdir. When the right arrow was pressed, Rdir would equal one. If the left arrow was pressed, Rdir equals 0. This is helpful for changing in the air. Anyway, when right arrow was pressed I would use:
(When (right arrow pressed) )
(set (Rdir) to (1))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))

and reverse for left arrow. Hope I answered your question

Offline

 

#5 2011-10-22 10:05:00

astroLoger
New Scratcher
Registered: 2011-10-16
Posts: 100+

Re: Rotate and Walk

astroLoger wrote:

I am currently developing a platformer called DRAINED and this was how I did it:

I created a variable called Rdir. When the right arrow was pressed, Rdir would equal one. If the left arrow was pressed, Rdir equals 0. This is helpful for changing in the air. Anyway, when right arrow was pressed I would use:
(When (right arrow pressed) )
(set (Rdir) to (1))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))
(glide (0.1) sec to x: ((xposition) + (7)) y: (yposition))
(switch to costume (whatever))

and reverse for left arrow. Hope I answered your question

Sorry, it got messed up by the automatic blocks.
Hopefully you got the just of it though.

Offline

 

#6 2011-10-24 18:27:38

Berserkbw
Scratcher
Registered: 2011-06-07
Posts: 17

Re: Rotate and Walk

Thanks guys!

Offline

 

#7 2011-10-24 19:25:29

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Rotate and Walk

The easiest way, if you just want the most simple code possible, is:
[blocks]
<when green flag clicked>
<forever>
<if><key[ left arrow ]pressed?
<turn cw( 3 )degrees>
<end>
<if><key[ right arrow ]pressed?>
<turn cw( 3 )degrees>
<end>
<move( 5 )steps>
<end>

I suppose that isn't the easiest way, but that's the best simple way.

Last edited by kayybee (2011-10-24 19:26:51)

Offline

 

Board footer