Bouncing Ball Physics | Sololearn: Learn to code for FREE!
Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję
+ 1

Bouncing Ball Physics

I want to make a satisfying bouncing ball with pygame, something like on social media videos that all we seen. Can anybody help me about it?

16th Jun 2024, 4:15 AM
Caner Ceylan
Caner Ceylan - avatar
3 odpowiedzi
+ 3
Well, my answer assume that you actually know basic Newtonian physics and force laws. Motion is the result of a force. This implies that when a force is applied to something, we expect a motion of the resultant force is not zero. According to newton, F = ma, but it's also correct to say that the function of force g(F) = motion. Mathematically in set, notation Motion = {g(F): m and ∑F ≠ 0} Now let make some instances, A ball will have different forces acting on it at different level, some are negligible while others like Gravity (F = mg), Drag (F = kv) and buoyancy (No formula) are important.. also forces are vector quantities so consider making a force model like strict Force { double x; double y; double z; // if 3d } Buoyancy has no predefined formula like gravity, this means you have to find the formula by yourself using the Archimedes principle. You will mostly consider the area of the ball πr^2, the density of atmosphere (P). Since F = P/A Bouyance = mgh / πr^2. (simplest case) Another force is the normal reaction, the static and dynamic friction when the ball is in contact with the ground. All this have no predefined formula but for simpler cases Normal = -weight = { x: x ∈ Z, -mg or sin(θ) * -mg if inclined} Friction= cos(theta) * -mg * k k at friction = {real numbers} The total of this force will work and make the ball bounce like a magic. Ps: take wall boundary collision also in consideration
17th Jun 2024, 4:57 PM
Melle
+ 2
Always assume your target audience has not seen any memes or YouTube videos ever, but only that they are aware memes and YouTube exist. I have little precision in interpreting “a satisfying bouncing ball, something like on social media videos.” Please provide an example. Meanwhile, just on a guess of what it is, you have two options: 1. Draw a circle animated on the Y axis to abs(sin(t)), or some other simple movement logic. This is easy but limited. Use if the ball will only be bouncing off of perfectly horizontal and vertical walls, not slants/curves or other balls. 2. Use Box2D physics engine. I have never done this in full, but it doesn’t look too hard and can almost certainly do what you want.
16th Jun 2024, 6:45 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 2
https://sololearn.com/compiler-playground/W3YhrLOXMR37/?ref=app U can check my javascript code to understand the physics behind bouncing ball and apply accordingly to ur python code
17th Jun 2024, 7:04 AM
Sky🌌🧑🏻‍🔬
Sky🌌🧑🏻‍🔬 - avatar