How to make bounces in Hopscotch?

helpwithcode

#1

Hey guys. I'm wondering if anyone knows how to create bouncing in Hopscotch. I need it for a game mechanic. Different kinds, such as a bouncy ball, trampoline, etc. would be helpful. And I don't mean set, unrealistic Change Y by blocks.

Is there a formula or something that creates realistic bouncing? Thanks!


#2

First do when Play button is tapped, then take out a (repeat forever), then take (change y by Gravity), then ,make a new value called gravity. Then take out a (increase Gravity by 1). Make a new rule when . bumps edge, then take out a set value block; (Gravity) to (what ever you want). Now you are done! I may make a video for this on my youtube channel Phase Studios(Hopscotch the App).


#3

Hi @CreativeCoder good question! I've wondered how to make bounce too. I learnt from a great tutorial by @Funky_63_Greenland and here it is:


https://c.gethopscotch.com/p/y8vj8mk

So like @Phase_Studios said, you can call the value "Gravity".

At the start, set Gravity to 0.
Then:

Repeat forever 
    Increase "Gravity" by -1 
    Change Y by "Gravity"
End

(in the picture it says repeat 99999 because there weren't any repeat forever blocks at the time, and the Increase Value block used to be called Change Value).

And when you want your object to bounce, add the code:

Set value "Gravity" to 25

So what the code is doing in the repeat forever is making gravity lower and lower, so the object changes Y lower and lower.

But when you make the value Gravity equal 25, the object will change Y by 25 and move up instead and it will bounce up. Then 25 will get smaller and smaller until it is negative because of the Increase Gravity by -1, and when it's negative that's when the object falls down again because then it will start changing Y by a negative number.

Hope this helps and feel free to ask for more clarification :smiley:


How do you make a simple platform game?
#4

Thanks @Phase_Studios and @t1_hopscotch! I'll be sure to credit you in the game!


#5

@CreativeCoder, how do you do the button thing? Please don't flag this.


#6

You can use the code [kbd]something[/kbd]


#7

[kbd]It doesn't work for me?[/kbd]


#11

Sorry, it's < and > not [ and ]
something


#12

Thank You so much @CreativeCoder!


#13

You're welcome @CreativeCoder!