## Discuss Scratch

gtar1
Scratcher
100+ posts

### Dune

I want to re-create the game Dune, if you've heard of it. It involves a ball, and when you hold, the ball comes down from it's jump faster, and if you land on a bump perfectly, you get more speed.

If they say the sky's the limit, then why are there footprints on the moon?

I hope this helps! If you need any further, clarification, just ask!
NormallyNormal
Scratcher
24 posts

### Dune

I know what game you are talking about

You haven't specified anything that you need to know but I can give you a few ideas.

The dunes could be comprised of sine/cosine waves being multiplied together. (the same kind of principle I used in this project: https://scratch.mit.edu/projects/200464164/ )

As for getting the ball to accelerate WITH the waves/dunes, I think the most efficient method would be to take the derivative of the dune equation to get the slope, then make a script that will use that to calculate the upwards velocity.

If you don't know derivatives that's fine. I'll get to that in the next paragraph.
For making the dune equation, go on the online graphing calculator called desmos and copy this into the equation box:
\cos\left(2.1x\right)\cdot\sin\left(3x\right)\cdot\cos\left(5x\right)\cdot\sin\left(6.2x\right)
then adjust the numbers until you get something you like.

Once you've got the equation you want (make sure to test it in scratch) use symbolab (online math solver) and paste this in:
\frac{d}{dx}\left(\cos \left(2.1x\right)\cdot \sin \left(3x\right)\cdot \cos \left(5x\right)\cdot \sin \left(6.2x\right)\right)
with your numbers instead of mine (edit them once it is pasted in). This will give you the derivative, which when you plug in an X, the result will be the slope of the equation at that X. You can use the slope to determine how fast upwards the player should go. It will probably be a pretty long equation so make sure when you translate it to scratch you don't make any mistakes.

This is fairly complex math so if you need further clarification, ask.

Last edited by NormallyNormal (Feb. 7, 2018 04:30:58)

I'm normal. Most of the time. I'm normally normal.
gtar1
Scratcher
100+ posts

### Dune

NormallyNormal wrote:

I know what game you are talking about

You haven't specified anything that you need to know but I can give you a few ideas.

The dunes could be comprised of sine/cosine waves being multiplied together. (the same kind of principle I used in this project: https://scratch.mit.edu/projects/200464164/ )

As for getting the ball to accelerate WITH the waves/dunes, I think the most efficient method would be to take the derivative of the dune equation to get the slope, then make a script that will use that to calculate the upwards velocity.

If you don't know derivatives that's fine. I'll get to that in the next paragraph.
For making the dune equation, go on the online graphing calculator called desmos and copy this into the equation box:
\cos\left(2.1x\right)\cdot\sin\left(3x\right)\cdot\cos\left(5x\right)\cdot\sin\left(6.2x\right)
then adjust the numbers until you get something you like.

Once you've got the equation you want (make sure to test it in scratch) use symbolab (online math solver) and paste this in:
\frac{d}{dx}\left(\cos \left(2.1x\right)\cdot \sin \left(3x\right)\cdot \cos \left(5x\right)\cdot \sin \left(6.2x\right)\right)
with your numbers instead of mine (edit them once it is pasted in). This will give you the derivative, which when you plug in an X, the result will be the slope of the equation at that X. You can use the slope to determine how fast upwards the player should go. It will probably be a pretty long equation so make sure when you translate it to scratch you don't make any mistakes.

This is fairly complex math so if you need further clarification, ask.
HOLY COW! This was EXACTLY what I was looking for! THANKS SO MUCH!!

If they say the sky's the limit, then why are there footprints on the moon?

I hope this helps! If you need any further, clarification, just ask!
gtar1
Scratcher
100+ posts

### Dune

NormallyNormal wrote:

I know what game you are talking about

You haven't specified anything that you need to know but I can give you a few ideas.

The dunes could be comprised of sine/cosine waves being multiplied together. (the same kind of principle I used in this project: https://scratch.mit.edu/projects/200464164/ )

As for getting the ball to accelerate WITH the waves/dunes, I think the most efficient method would be to take the derivative of the dune equation to get the slope, then make a script that will use that to calculate the upwards velocity.

If you don't know derivatives that's fine. I'll get to that in the next paragraph.
For making the dune equation, go on the online graphing calculator called desmos and copy this into the equation box:
\cos\left(2.1x\right)\cdot\sin\left(3x\right)\cdot\cos\left(5x\right)\cdot\sin\left(6.2x\right)
then adjust the numbers until you get something you like.

Once you've got the equation you want (make sure to test it in scratch) use symbolab (online math solver) and paste this in:
\frac{d}{dx}\left(\cos \left(2.1x\right)\cdot \sin \left(3x\right)\cdot \cos \left(5x\right)\cdot \sin \left(6.2x\right)\right)
with your numbers instead of mine (edit them once it is pasted in). This will give you the derivative, which when you plug in an X, the result will be the slope of the equation at that X. You can use the slope to determine how fast upwards the player should go. It will probably be a pretty long equation so make sure when you translate it to scratch you don't make any mistakes.

This is fairly complex math so if you need further clarification, ask.
One thing: For the first step, what should i do with the var x, and should I do something like
pen downset x to (the formula)

If they say the sky's the limit, then why are there footprints on the moon?

I hope this helps! If you need any further, clarification, just ask!
gtar1
Scratcher
100+ posts

### Dune

NormallyNormal wrote:

I know what game you are talking about

You haven't specified anything that you need to know but I can give you a few ideas.

The dunes could be comprised of sine/cosine waves being multiplied together. (the same kind of principle I used in this project: https://scratch.mit.edu/projects/200464164/ )

As for getting the ball to accelerate WITH the waves/dunes, I think the most efficient method would be to take the derivative of the dune equation to get the slope, then make a script that will use that to calculate the upwards velocity.

If you don't know derivatives that's fine. I'll get to that in the next paragraph.
For making the dune equation, go on the online graphing calculator called desmos and copy this into the equation box:
\cos\left(2.1x\right)\cdot\sin\left(3x\right)\cdot\cos\left(5x\right)\cdot\sin\left(6.2x\right)
then adjust the numbers until you get something you like.

Once you've got the equation you want (make sure to test it in scratch) use symbolab (online math solver) and paste this in:
\frac{d}{dx}\left(\cos \left(2.1x\right)\cdot \sin \left(3x\right)\cdot \cos \left(5x\right)\cdot \sin \left(6.2x\right)\right)
with your numbers instead of mine (edit them once it is pasted in). This will give you the derivative, which when you plug in an X, the result will be the slope of the equation at that X. You can use the slope to determine how fast upwards the player should go. It will probably be a pretty long equation so make sure when you translate it to scratch you don't make any mistakes.

This is fairly complex math so if you need further clarification, ask.
Also, how do I test it in scratch?

If they say the sky's the limit, then why are there footprints on the moon?

I hope this helps! If you need any further, clarification, just ask!
NormallyNormal
Scratcher
24 posts

### Dune

You would do something like this below, and replace the numbers like 1.1 and 0.52 in the render dunes block with your own that you decided on. It might look a little different in scratch (stretched out, compressed, etc.) so that's why you should test it. You can use the code from this if you want but I'm not sure how optimized it is. The change x by (number) controls how fast the scrolling is.
https://scratch.mit.edu/projects/203019554/

Edit: Also make sure to change the numbers to the same thing in the player sprite.

Last edited by NormallyNormal (Feb. 9, 2018 00:12:48)

I'm normal. Most of the time. I'm normally normal.
gtar1
Scratcher
100+ posts

### Dune

NormallyNormal wrote:

You would do something like this below, and replace the numbers like 1.1 and 0.52 in the render dunes block with your own that you decided on. It might look a little different in scratch (stretched out, compressed, etc.) so that's why you should test it. You can use the code from this if you want but I'm not sure how optimized it is. The change x by (number) controls how fast the scrolling is.
https://scratch.mit.edu/projects/203019554/

Edit: Also make sure to change the numbers to the same thing in the player sprite.
Thanks! That helps a lot!

If they say the sky's the limit, then why are there footprints on the moon?

I hope this helps! If you need any further, clarification, just ask!
NormallyNormal
Scratcher
24 posts

### Dune

Basically, imagine you were a car driving along the curve. If you flew off the curve, the orange line is the direction you would fly off in.

I'm normal. Most of the time. I'm normally normal.
gtar1
Scratcher
100+ posts

### Dune

NormallyNormal wrote:

Basically, imagine you were a car driving along the curve. If you flew off the curve, the orange line is the direction you would fly off in.
thxs

If they say the sky's the limit, then why are there footprints on the moon?

I hope this helps! If you need any further, clarification, just ask!
gtar1
Scratcher
100+ posts

### Dune

NormallyNormal wrote: