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

#1 2008-02-12 15:52:50

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Back to the basics!

yes... I know to some multi-lingual programers ( I mean you know many programming languages!) this is basic stuff, but others may find this interesting. I am going to show you how the move() steps block works.

Basically to move right:

When key right arrow pressed:
Change x by (sin of direction)
Change y be (cos of direction)

When key left arrow pressed:
Change x by ((sin of direction) * -1)
Change x by ((cos of direction) * -1)

When key up arrow pressed:
Change x by (cos of direction)
Change y be (sin of direction)

When key down arrow pressed:
Change x by ((cos of direction) * -1)
Change x by ((sin of direction) * -1)


Hope you learnt something new!


Burn baby Burn!

Offline

 

#2 2008-02-12 16:20:46

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Back to the basics!

I think what you are trying to show here, is how Scratch computes (behind the scenes, as it were) the new X and Y coordinates after a Move command.  Scratch is using trigonometry to turn the motion in a given direction into new X and Y coordinates.  This might be helpful for folks who are trying to get a handle on how Trig functions work.

I think you have an error though, all of the Cos and Sin functions should be multiplied by the number of steps that the sprite is moving in the given direction, for example:

                  Change x by Steps * (sin of direction)


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2008-02-13 12:49:25

messd002
Scratcher
Registered: 2007-12-07
Posts: 100+

Re: Back to the basics!

I suppose thats what I am trying to show, however as far as I know there are no errors, as I tested this. This was only meant to make a sprite move one pixel mind.


Burn baby Burn!

Offline

 

Board footer