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
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
Offline
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.
Offline
if you want to move in a certain direction, but don't want to use the
move (10) stepsblock 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)
Offline
TRocket wrote:
if you want to move in a certain direction, but don't want to use the
move (10) stepsblock you can usechange 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.
Offline
7734f wrote:
TRocket wrote:
if you want to move in a certain direction, but don't want to use the
move (10) stepsblock you can usechange 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
Hi All,
Many thanks for everyone for their help
Paul
Offline