## Discuss Scratch

- Discussion Forums
- » Help With Scripts
- » Dune

- 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.

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

HOLY COW! This was EXACTLY what I was looking for! THANKS SO MUCH!! 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.

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

One thing: For the first step, what should i do with the var x, and should I do something like 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.

pen down

set 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

Also, how do I test it in scratch? 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.

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.

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

Thanks! That helps a lot! 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.

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

This might help you understand derivatives a bit more: https://www.desmos.com/calculator/byotbuhlmf

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.

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

https://www.desmos.com/calculator/byotbuhlmfthxs This might help you understand derivatives a bit more:

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.

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

https://www.desmos.com/calculator/byotbuhlmfIs it possible for you to show me how to make a derivative too? This might help you understand derivatives a bit more:

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.

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!

- Discussion Forums
- » Help With Scripts
- » Dune