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

#1 2008-03-16 00:07:46

adriangl
Scratcher
Registered: 2007-07-02
Posts: 1000+

i can scroll, but can't use velocity

I have learned how to scroll from looking at other projects, but i don't know how to use velocity.


Scratchin' since 2007

Offline

 

#2 2008-03-16 03:08:37

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: i can scroll, but can't use velocity

Velocity simply means speed* - I suspect the component that is actually giving you trouble is acceleration, where the speed is gradually increased or decreased instead of being a simple stop/start.

To use acceleration and velocity, you need to replace the command that makes your sprite take a step forward of a fixed amount (eg "move 5 steps") with a command that increases or decreases a variable "speed", and then moves a step of that speed.

EG

[blocks]
<forever>
<if><key[ up arrow ]pressed?>
<change{  speed }by( 1)
<end>
<move( <{ speed }> )steps>
<end>

[/blocks]

If you want the sprite to automatically slow down when not speeding up (the method used in many platformers)

[blocks]
<forever>
<if> <key[ up arrow ]pressed?>
<change{  speed }by( 1)
<else>
<if> <( <{ speed  }> <>> 0 )>
. <change{  speed }by( -1)
. <end>
<end>
<move( <{ speed  }> )steps>
<end>

[/blocks]

*(For true mathematicians/physicists it actually means speed AND direction)

Last edited by Mayhem (2008-03-16 03:15:55)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2008-03-16 10:25:53

adriangl
Scratcher
Registered: 2007-07-02
Posts: 1000+

Re: i can scroll, but can't use velocity

thanks!


Scratchin' since 2007

Offline

 

Board footer