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

#1 2007-09-15 19:53:45

yazzo
Scratcher
Registered: 2007-09-15
Posts: 5

need help

im trying to create a racing game but cant get find a way to get the up arrow to always propel the car the way the front is facing. Any sugestions would be appreciated

Offline

 

#2 2007-09-15 20:03:26

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

Re: need help

<when green flag clicked>
<forever if><key[ up arrow ]pressed?>
<move( 5 )steps>


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

 

#3 2007-09-17 04:26:43

yazzo
Scratcher
Registered: 2007-09-15
Posts: 5

Re: need help

hi archmage, im more sort of looking for something more real so that the doesnt just stop when you depress the up arrow i am trying to use the marble racer, (you can access it in the games file that come with scratch when you download it),  style of movement so that its not just going or not going that it slowly accelerates and when you arent pressing up it slowly decreases in speed and then finally stops without starting to go backwards. 

thanks anyway, Isaac

Last edited by yazzo (2007-09-17 05:19:40)

Offline

 

#4 2007-09-17 08:22:20

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

Re: need help

Oh you want acceleration? Thats simple

Create 3 variables
acceleration and max acceleration and speed

//This all goes on your car sprite
<when green flag clicked>
<forever>
<move( <{ speed }> )steps>
<if><<  <not> <( <{ speed }> <=> 0 )> >>
<if><( <{  speed}> <>>0  )>
<change{ speed }by(-1
<else>
<change{ speed }by(1

<when green flag clicked>
<forever if><key[up arrow ]pressed?>
<if><abs( speed< <{ maxaccelaration }>
<change{ speed }by( <{  acceleration}>

<when green flag clicked>
<forever if><key[down arrow ]pressed?>
<if><abs( speed < <{ maxaccelaration }>
<change{ speed }by( <{  acceleration*-1}>

Edited so that the variable names suit their roles.

Last edited by archmage (2007-09-17 22:34:20)


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

 

#5 2007-09-17 08:27:07

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: need help

Yazzo,

Take a look at: http://scratch.mit.edu/projects/EdnaC/34922

This demo was put together (in response to another posting) to show a way to do almost exactly what you are asking for .  The Jet will slowly "throttle up" in speed, and will slow down on its own if the (up arrow) isn't pressed.  Pressing down arrow will slow the plane down more rapidly. 

The plane never stops, but you can fiddle with the numbers to make it do what you want.  Hope this helps.

-Mr Ed

Offline

 

#6 2007-09-17 21:31:24

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: need help

Minor comment to archmage: you have the meanings of acceleration and speed swapped in your example.  If you have a time step of delta_t seconds, then
   change velocity by acceleration * delta_t
on each time step.

Offline

 

#7 2007-09-17 21:38:13

yazzo
Scratcher
Registered: 2007-09-15
Posts: 5

Re: need help

ty(thankyou)very much everyone

Offline

 

#8 2007-09-18 05:11:10

yazzo
Scratcher
Registered: 2007-09-15
Posts: 5

Re: need help

hey guys thx 4 all your help but im just wondering if you can do this same thing for sideways motion for a drifting effect. thx again

P.S archmage while you might consider this simple i have had barely 5 hours playing at scratch so you can consider me "new" to it for now

Offline

 

#9 2007-09-18 19:23:45

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: need help

Anything you can do in the y direction you can also do in the x direction.

Offline

 

#10 2007-09-18 19:34:48

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

Re: need help

yazzo wrote:

P.S archmage while you might consider this simple i have had barely 5 hours playing at scratch so you can consider me "new" to it for now

You were the one who wanted the codes, all I did was provide them.  smile


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

 

#11 2007-09-19 13:08:22

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: need help

yazzo wrote:

hey guys thx 4 all your help but im just wondering if you can do this same thing for sideways motion for a drifting effect. thx again

P.S archmage while you might consider this simple i have had barely 5 hours playing at scratch so you can consider me "new" to it for now

whilst having a car move forwards and drive in a way similar to archmages suggestion i think it would be quite hard to make it drift.  i have tried a couple of times (unsuccessfully) to make a car that drifts. 
if anyone knows how or has ideas i would love to know.


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#12 2007-09-19 17:09:57

yazzo
Scratcher
Registered: 2007-09-15
Posts: 5

Re: need help

archmage wrote:

yazzo wrote:

P.S archmage while you might consider this simple i have had barely 5 hours playing at scratch so you can consider me "new" to it for now

You were the one who wanted the codes, all I did was provide them.  smile

and im thankful  big_smile

Offline

 

#13 2007-09-20 20:01:49

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: need help

BigB,

Here's an attempt at "Drifting":

http://scratch.mit.edu/projects/EdnaC/37943

Lots of tweaking to do.  Play with how "Slip" and "Slide" are calculated in the Car's script.  No real physics, this is a fudge put together based on ideas that I used in "Spaceship".

Yazzo,

If I interpret what you want correctly, it's to have the arrow keys add and subtract "velocity" to a sprite when pressed (and held).  So, bumping "up" arrow would start the ball and it would continue in the up direction slowly, pressing again or holding longer would make it go faster, pressing down would slow it or even reverse direction.

One way to do this would be to use a hidden sprite that moves in X and Y, and have the visible sprite (the Marble), "go to" the hidden one.  Create two variables, (I'd call them) Velocity_X and Velocity_Y.

1) Use a loop that runs constantly to look for the arrow keys, (if key "Up" pressed) and have that loop adjust the value of Velocity_X and Velocity_Y.

2) Have the hidden sprite "go to" the Marble, then have the hidden sprite "change X (by the amount of the Velocity_X variable) and likewise for Y.

3) Have the Marble "go to" the hidden sprite.

4) Repeat

(The hidden sprite keeps you from moving the Marble in a "stairstep" of x/y moves.)

Hope that helps...

Last edited by EdnaC (2007-09-21 08:30:59)

Offline

 

Board footer