[SG] PixelGrid 6

Posted by Stained Glass on May 4, 2008, 5:24 p.m.

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 6

1. Guardian by Tremulant

2. soundsoiso by tomic

3. Edgar Allan Poe CGA by Skurwy87

4. Rust Mesa by Larwick

5. spacecity by KaptenBolmare

6. Me And My Dog On Acid, Yesterday by iLKke

7. Stone Face by Lawrence

8. R U sure your mom let me stay? by Fool

9. Shiba Inu by Panda

Comments

Juju 16 years, 6 months ago

Remember - p = mv. Since we are consider two objects in a system, we include both in our equation:

p = m1 * u1 + m2 + u2

Also, momentum must be conserved, so moment after must equal momentum to begin with:

m1 * v1 + m2 * v2 = m1 * u1 + m2 * u2

Considering 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 * v1

Therefore:

m1 * v1 + m2 * (k * v1) = p

v1 * (m1 + k * m2) = p

Then 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!

ESA 16 years, 6 months ago

Skurwy's one has an excellent color choice. Great work here, I love pixel art.

Unaligned 16 years, 6 months ago

@Juju: I was doing that exact same thing today at physics class.

This blog's pixel grid is nice, as always

Polystyrene Man 16 years, 6 months ago

Poe's hair is ridiculously good.