Hello. This past week has been very fustrating because I began to make a simple physics engnie that involved blocks, but I have been racking my brain to try to get it all to work and I just can't get it. The problem is that I cannot get objects to interact with each other perfectly. All I wanted to have in the engine was square objects be able to bounce, have friction, and be able to transfer their momentum to other blocks, but the last one I cannot get. I guess I might figure it out sometime, but if you have anything that you think might be useful, please post. If you would like to look at the file it can be found here: throw_bounce.gmk I know the code is messy, but the brain of it all is in the step event of obj_object. I would love some help on it.PixelGrid 61. Guardian by Tremulant2. soundsoiso by tomic3. Edgar Allan Poe CGA by Skurwy874. Rust Mesa by Larwick5. spacecity by KaptenBolmare6. Me And My Dog On Acid, Yesterday by iLKke7. Stone Face by Lawrence8. R U sure your mom let me stay? by Fool9. Shiba Inu by Panda
Remember - p = mv. Since we are consider two objects in a system, we include both in our equation:
p = m1 * u1 + m2 + u2Also, momentum must be conserved, so moment after must equal momentum to begin with:m1 * v1 + m2 * v2 = m1 * u1 + m2 * u2Considering we know all m and u, there are variables to calculate, v1 and v2. Therefore we need another equation that uses v1 and/or v2. The simplest is just a ratio of velocities that indicates the constant of elasticity:v2 = k * v1Therefore:m1 * v1 + m2 * (k * v1) = pv1 * (m1 + k * m2) = pThen rearrange to give the velocity of the first object and hence the velocity of the second object. It can also be done in terms of energy (energy being the integral of momentum with respect to velocity). Inelastic collisions have an extremely high value for k (as I suspect you'd want for two boxes colliding together). You can also calculate k with:k = 1/(h1 * h2)Where h is an arbitary hardness constant, higher meaning harder. That way, you can attribute different properites to different objects and have them behave in realistic ways without needing to program in an independant value of k for each bod collision.Hope that helps!Skurwy's one has an excellent color choice. Great work here, I love pixel art.
@Juju: I was doing that exact same thing today at physics class.
This blog's pixel grid is nice, as alwaysPoe's hair is ridiculously good.