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

#1 2010-05-25 18:39:08

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

I need a good equation!

I am trying to change a variable.

I want the variable to get smaller, preferably logrhythmically (sp?) as the score increases.

Here's the deal. I have a sprite that needs to move from one side of the screen to the other.

Glide (VARIABLE SPEED) secs to x, y.

Since my variable is the length of time it takes to cross the screen, as the variable gets smaller, the sprite will cross faster.

What I currently have is:

pick random [.5 * (score + 5)/(score + 2)]  to [.6 * (score + 5)/(score + 1)]

This works pretty well, but it doesn't start out high enough (about 2.4), and it quickly drops to about .6 seconds.  I like the .6 at the end, but I'd like it to start at about 5 and drop to .6 over a period of about 20 iterations.

here's the current math examples.

Score 0 (starting)     1.25 to 3
Score 1                   1 to 1.8
Score 2                  .675 to 1.4
Score 3                   .8 to 1.2
Score 4                  .75 to 1.08
Score 5                  .71 to .996
Score 6, well, you get the general idea.

Any suggestions for a better equation?

Here's the link!

Thanks!

Last edited by infinitum3d (2010-05-25 19:49:10)

Offline

 

#2 2010-05-25 19:05:22

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: I need a good equation!

Here's an equation that might do what you want:

speed= starting speed * ratio^score

For the speed to go down as the score goes up, the ratio must be less than 1.

Say you want the speed variable to start out at 16 and you want it to be cut in half every time the score goes up by one. The equation would be:

speed= 16 * .5^score

Of course, you can't make a script that looks like that because Scratch doesn't have exponents. Using a handy-dandy log trick, you get this, which works the same way:

http://img27.imageshack.us/img27/1577/logscoreandspeed.gif

To randomize it, you could try something like this:
http://img19.imageshack.us/img19/7594/randomizescoreandspeed.gif

Does that help? Does it do what you want?

Last edited by scmb1 (2010-05-25 19:30:12)


http://i48.tinypic.com/2z5pqad.png

Offline

 

#3 2010-05-25 19:50:27

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: I need a good equation!

That looks great! I'll test it out!!!!








Link to Project!

Offline

 

Board footer