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

#1 2013-03-29 18:34:09

pjwilliams
New Scratcher
Registered: 2013-03-29
Posts: 2

Making a script move in the direction in which it is pointing

Hi there,
I have a script which I wish to move around the stage by use of the arrow keys.

Left  -rotate 1 degree left
Right -rotate 1 degree right
up  -move in the direction in which the sprite is pointing
down -move in the opposite direction to which the sprite is pointing

I cannot find a simple way of linking the direction to the corresponding x and y movements

Offline

 

#2 2013-03-29 19:54:36

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: Making a script move in the direction in which it is pointing

Here:

when gf clicked
forever//always checks for what's inside and to see if something's happening
 if <key [left arrow v] pressed?>//if something happens, it does the action in the loop
  turn ccw (1) degrees
 end
  if <key [right arrow v] pressed?>
   turn cw (1) degrees
  end
  if <key [up arrow v] pressed?>
   move (5) steps//moves 5 steps in that direction
  end
  if <key [down arrow v] pressed?>
   move (-5) steps//moves  backwards 5 steps 
  end


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#3 2013-03-29 20:25:03

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Making a script move in the direction in which it is pointing

Yeah, the secret to this is the move block. Its a bit ambiguous, but the move block will push the sprite forward in any direction it is facing. This can also be replicated with the use of trig functions but that isn't necessary.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#4 2013-03-29 20:45:32

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: Making a script move in the direction in which it is pointing

Shouldn't this go in Help with Scripts?


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#5 2013-03-29 21:36:09

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: Making a script move in the direction in which it is pointing

Mokat wrote:

Shouldn't this go in Help with Scripts?

It is  roll  Lol.


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#6 2013-03-29 23:12:55

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: Making a script move in the direction in which it is pointing

7734f wrote:

Mokat wrote:

Shouldn't this go in Help with Scripts?

It is  roll  Lol.

Maybe he posted before it was moved, if it was moved, and you saw it after it was moved.
You never know  tongue


http://i46.tinypic.com/3148ksz.gif

Offline

 

#7 2013-03-30 07:53:18

TRocket
Scratcher
Registered: 2009-08-18
Posts: 1000+

Re: Making a script move in the direction in which it is pointing

if you want to move in a certain direction, but don't want to use the

move (10) steps
block you can use
change x by (([sin v] of (direction))*(10))
change y by (([cos v] of (direction))*(10))

Last edited by TRocket (2013-03-30 07:54:21)


http://i.imgur.com/1QqnHxQ.png

Offline

 

#8 2013-03-30 09:47:46

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: Making a script move in the direction in which it is pointing

TRocket wrote:

if you want to move in a certain direction, but don't want to use the

move (10) steps
block you can use
change x by (([sin v] of (direction))*(10))
change y by (([cos v] of (direction))*(10))

I think that's a wee bit complicated for a New Scratcher.


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#9 2013-03-30 11:57:23

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: Making a script move in the direction in which it is pointing

7734f wrote:

TRocket wrote:

if you want to move in a certain direction, but don't want to use the

move (10) steps
block you can use
change x by (([sin v] of (direction))*(10))
change y by (([cos v] of (direction))*(10))

I think that's a wee bit complicated for a New Scratcher.

Just because they're a new scratcher doen't mean that they don't understand trig and other complicated maths. I'm a new scratcher and I understand trig and know a reasonable amount of squeak. Just because the account is new doesn't mean that they are new to scratch and/or programming in general.

Offline

 

#10 2013-03-31 10:26:19

pjwilliams
New Scratcher
Registered: 2013-03-29
Posts: 2

Re: Making a script move in the direction in which it is pointing

Hi All,

Many thanks for everyone for their help

Paul

Offline

 

Board footer