Discuss Scratch

Haycat2009
Scratcher
44 posts

Bouncing within a circle

Hi, can you please any provide links for physics engines for bouncing inside/within circles, without gravity? Thanks!
RicDiamond1477
Scratcher
100+ posts

Bouncing within a circle

If you are trying to make something like that without gravity just make it to detect if it is touching the circle and go the opposite way or a similar angle.
deck26
Scratcher
1000+ posts

Bouncing within a circle

RicDiamond1477 wrote:

If you are trying to make something like that without gravity just make it to detect if it is touching the circle and go the opposite way or a similar angle.
What do you mean by the opposite way or a similar angle? You can't just bounce back in a sensible direction by turning 180 degrees so you make it sound simple but have given no information on how to actually do it.

I believe what you are effectively doing is bouncing off a tangent to the circle at the point of intersection. So the equation shown here https://scratch.mit.edu/projects/99412537 will work on that basis.

Work out where the point of intersection is (presumably a ‘touching’ block). Using trig you can work out the angle from that point to the centre of the circle. Now add 90 degrees to that angle to get the tangent. Now you have the approach angle A and surface angle S.

Last edited by deck26 (Jan. 23, 2025 09:47:06)

RokCoder
Scratcher
1000+ posts

Bouncing within a circle

Here's a simple project on my test account that does what you want (and effectively what @deck26 has described). You can set the gravity to any value (so zero in your case). You can also alter the restitution value which affects how much energy a bounce takes from the ball - for perfectly elastic collisions that go on forever, set this to zero.
Haycat2009
Scratcher
44 posts

Bouncing within a circle

Thanks! Needed the engine for a game (the old engine would break if the ball was too fast. Too fast as in 20u/second. )
Haycat2009
Scratcher
44 posts

Bouncing within a circle

Does anyone have a 0% pen version? The way I am using it is imcompatible with pen.
deck26
Scratcher
1000+ posts

Bouncing within a circle

You can work out if you've hit the circle when the current coordinates are a radius length (plus or minus one pixel perhaps) away from the circle's centre which is all doable with Pythagoras Theorem. Then trig allows you to rowk out the angle to the centre and therefore the angle of the tangent.
10goto10
Scratcher
500+ posts

Bouncing within a circle

Using the math described would be the right way to go, but, I did make a small study of having a sprite bounce around a sprite circle. It ‘mechanically” determines the angle to bounce. It’s here: https://scratch.mit.edu/projects/1125339940/

This probably is not the physic engine you are looking for but might be worth a look.

Powered by DjangoBB