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

#1 2012-05-03 08:45:48

superpear
Scratcher
Registered: 2009-12-17
Posts: 42

Acceleration scripts

How do you make a script/scripts for speeding up then slowing down?


http://scratch.mit.edu/static/projects/superpear/2487301_sm.png<CLICK!>http://scratch.mit.edu/static/projects/superpear/2515102_sm.png

Offline

 

#2 2012-05-03 09:57:36

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Acceleration scripts

Create an "xspeed" variable and an "xmax" variable. Set xmax to, say, 4. Then, do a script like this:

forever
set [xmax] to (4) 
if < key [right arrow v] presed >
 set [xvel v] to 0
 forever if < key [right arrow v] pressed >
  change x by (xvel)
  change [xvel v] by (1)
   if < <(xvel) > (xmax) > >
    set [xvel] to (xmax)
 


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#3 2012-05-03 16:52:07

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Acceleration scripts

^ you kinda forgot a deceleration script...


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#4 2012-05-04 09:19:48

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Acceleration scripts

mythbusteranimator wrote:

Create an "xspeed" variable and an "xmax" variable. Set xmax to, say, 4. Then, do a script like this:

when gf clicked
forever
set [xmax v] to [4] 
if <key [right arrow v] pressed ?>
 set [xvel v] to (0)
 forever if <key [right arrow v] pressed ?>
  change x by (xvel)
  change [xvel v] by (1)
   if <(xvel) > (xmax)>
    set [xvel v] to (xmax)
 

Fixed your scripts.


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#5 2012-05-04 09:44:01

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Acceleration scripts

Give this a try:

Create a variable called "Velocity" and another one called "LKP" and use this script:

when gf clicked
set [Velocity v] to [0]
forever
  if <key [left arrow v] pressed?>
    set [LKP v] to [1]
    change [Velocity v] by (-0.5)
  end
  if <key [right arrow v] pressed?>
    set [LKP v] to [2]
    change [Velocity v] by (0.5)
  end
  if <(Velocity) > (4)>
    set [Velocity v] to (4)
  end
  if <(Velocity) < (-4)>
    set [Velocity v] to (-4)
  end
  if <<<(LKP) = [1]> and <(Velocity) > (0)>> or <<(LKP) = [2]> and <(Velocity) < (0)>>>
    set [Velocity v] to [0]
  end
  set [Velocity v] to ((Velocity) * (0.8))
  change x by (Velocity)
end

Last edited by SciTecCf (2012-05-04 10:31:53)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#6 2012-05-04 09:55:20

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Acceleration scripts

SciTecCf wrote:

Give this a try:

Create a variable called "Velocity" and another one called "LKP" and use this script:

when gf clicked
set [Velocity v] to [0]
forever
  if <key [left arrow v] pressed?>
    set [LKP v] to [1]
    change [Velocity v] by (-0.5)
  end
  if <key [right arrow v] pressed?>
    set [LKP v] to [2]
    change [Velocity v] by (0.5)
  end
  if <(Velocity) > (4)>
    set [Velocity v] to (4)
  end
  if <(Velocity) < (-4)>
    set [Velocity v] to (-4)
  end
  if <<<(LKP) = [1]> and <(Velocity) > (0)>> or <<(LKP) = [2]> and <(Velocity) < (0)>>>
    set [Velocity v] to [0]
  end
  set (Velocity) to ((Velocity) * (0.7))
  change x by (Velocity)
end

What is "LKP"?


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#7 2012-05-04 10:12:55

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Acceleration scripts

mythbusteranimator wrote:

SciTecCf wrote:

Give this a try:

Create a variable called "Velocity" and another one called "LKP" and use this script:

when gf clicked
set [Velocity v] to [0]
forever
  if <key [left arrow v] pressed?>
    set [LKP v] to [1]
    change [Velocity v] by (-0.5)
  end
  if <key [right arrow v] pressed?>
    set [LKP v] to [2]
    change [Velocity v] by (0.5)
  end
  if <(Velocity) > (4)>
    set [Velocity v] to (4)
  end
  if <(Velocity) < (-4)>
    set [Velocity v] to (-4)
  end
  if <<<(LKP) = [1]> and <(Velocity) > (0)>> or <<(LKP) = [2]> and <(Velocity) < (0)>>>
    set [Velocity v] to [0]
  end
  set (Velocity) to ((Velocity) * (0.7))
  change x by (Velocity)
end

What is "LKP"?

Last Key Pressed.

Last edited by SciTecCf (2012-05-04 10:13:51)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

#8 2012-05-04 10:38:37

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Acceleration scripts

SciTecCf wrote:

Give this a try:

Create a variable called "Velocity" and another one called "LKP" and use this script:

when gf clicked
set [Velocity v] to [0]
forever
  if <key [left arrow v] pressed?>
    set [LKP v] to [1]
    change [Velocity v] by (-0.5)
  end
  if <key [right arrow v] pressed?>
    set [LKP v] to [2]
    change [Velocity v] by (0.5)
  end
  if <(Velocity) > (4)>
    set [Velocity v] to (4)
  end
  if <(Velocity) < (-4)>
    set [Velocity v] to (-4)
  end
  if <<<(LKP) = [1]> and <(Velocity) > (0)>> or <<(LKP) = [2]> and <(Velocity) < (0)>>>
    set [Velocity v] to [0]
  end
  set [Velocity v] to ((Velocity) * (0.8))
  change x by (Velocity)
end

Here's an example: Velocity Movement Example

Last edited by SciTecCf (2012-05-04 10:40:20)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

Board footer