Bounce at relevant angles

hopscotch
helpwithcode

#1

How do I code an item to continuous bounce off other items and the edges at the angle relevant to the angle it hit the wall at (similarly to how a pool ball reflects off other balls and the edges of the pool table).


#2

Hm. The only way I know how to do that...
Oh! Wait! I'm not on Hopscotch for the summer, so I can't test it out, but do something with the angle value-thing for your character, and then when it hits something, just make it turn (360(- or +; depends)(Object Angle)) and then move forward!
Sorry for the unclear explanation...it might not work, and I recommend asking a more experienced Hopscotchers than I.


#3

I've made a project that does that nearly perfect.
My physics Maths is right, it's just the Hopscotch app can't handle enough decimals.
I'll publish and lost a link here.


#4

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

Here it is.
Drag the sun where you want.
When you tap the ball it shoots towards the sun.
This has gravity.


#5

Welcome to the forum!
Everyone's really nice :3
Sorry, I can't help with that but if you need help again, just tag me (@Rainboom) and I'll see what I can do!


#6

Thanks for giving me an idea to try. When I did that, it just did a loop-dee loop???? I have only played with Hopscotch for about a week with zero previous coding experience....so totally could be an error on my end of following your suggestion!


#7

Thanks so much for helping me. I have only been playing with hopscotch for about a week with zero prior coding experience - I'm really confused by how you did what you did. Can you maybe explain it a bit? Also, what I'm trying to get is for it to continuously bounce around (kind of like the old Atari ping pong game)????? However, if I can understand how you did the drop ball with a bounce, that will come in handy too for another idea I want to play with! :slight_smile:


#8

Thank you:) I just started playing around with hopscotch a week ago so I might have a ton of questions! :grinning:


#9

In a few days i'll post a link for the ball to move like a ball on a pool table.
I just have to make some minor tweaks.
I made the project a pool table ball before i added gravity

Ball code for vertical bounce+gravity

Set a value"YV" to 0

Repeat forever, set position to Y position of self + YV, Set X position ??

Repeat forever, Check if Y position of self is greater than 0
Increase "YV" by (1/16)

When Y position is less than 5
Set "YV" to (0+YV) /1.2

When Y position is less than 5
Change y by 1

"This stops the ball falling through the bottom of the screen when the balls moving slow or not moving"