Guest here, can someone explain to me how gravity works. I'm trying to code a quick platformer game in C++, but my program isn't working the way I wanted it to. My programming is flawless (and by that I mean it does what I want it to do), the only problem is that I'm having it do something that bastardizes physics. As you can probably guess, I've never taken a physics class before.
Gravity is a force that moves objects down at a certain rate, but how does the ground cancel out that force? Does the ground also create a force that cancels out gravity's force?
Also, how would you go about creating a gravity program?
Name:
Anonymous2009-11-29 22:34
Newton's Laws of Motion
Name:
Anonymous2009-11-29 22:40
Update: I just read somewhere that gravity is not a force but a curvature of spacetime. I doubt Newton's law of motion would be any help for gravity.
Name:
Anonymous2009-11-29 22:41
While its probably more suited for /prog/- although they're nothing but trolls- you'd probably have things like hitboxes and collision detection for any sort of platformer, so typically you'd have a variable that stores y-velocity for a given entity, and 'gravity' would simply add a static amount to it every update. You could even have a pseudo air-resistance by making a maximum downward velocity and such, but this is all stuff you can learn from tutorials and not so much from a math and science board.
Name:
Anonymous2009-11-29 22:51
>>4
>While its probably more suited for /prog/- although they're nothing but trolls
Hence the reason why I asked it here. They try too hard to be funny on /prog/.
I'm just wondering how to code gravity. Making a gravity force push down an object is easy enough, but how is the ground supposed to react to the object being pushed by gravity? Should the ground be a force that is equivalent to gravity's force?
Name:
Anonymous2009-11-29 23:51
If you have a sprite affected by gravity, it will move down until the frame it moves through the ground tile. You need to detect this, calculate the displacement required to correct the sprite to ground level, and then apply that to the sprite, then draw the screen.
Typically the ground wouldn't feel anything. It is static, unless you are doing something with malleable terrain, in which case i don't know.
Name:
Anonymous2009-11-30 1:44
how does it feel for nearly no one know that this boar exist
>>7
Since I am not the board itself and only a member, my feelings are not hurt. In all honesty, it feels pretty kvlt. How does it feel to need two tries to spell "board" correctly?
Again, this isn't a programming related issue. The problem here is that I fail at physics. What exactly is a ground force? And how does it keep an equilibrium with gravity's force?
You're confusing the force with velocity. When the upward force is more than 10, the object accelerates upwards.
Just set the the velocity to zero as soon as it touches the ground. The impulse supplied from the ground is essentially instantaneous.
Name:
Anonymous2009-11-30 14:09
>>11
To add, force is proportional to acceleration, not velocity.
In real life, the instaneous infinite of force is avoided by the object and the ground deforming upon impact, possibly involving bouncing. But you're programming a platformer, not a sophisticated physics simulation.
>>3
You don't need to bother with any of that curvature of space time horseshit. You don't even need to bother with Newton's Law of Universal Gravitation. All you need to know is that gravity is a force that always pulls objects down. The magnitude of this force depends on the object's mass. When the net force on an object is not zero, it will accelerate or change velocity. (Newton's Second Law of Motion)
What exactly is a ground force? And how does it keep an equilibrium with gravity's force?
The "ground force" is a reaction to the force of the object hitting the ground. Object exerts force on ground --> ground exerts equal and opposite force on object. (Newton's Third Law of Motion)
An object resting on the ground will have the force of gravity pushing it downwards and a force from the ground of the same magnitude pushing it up. This is static equilibrium.
Collisions are trickier and I've wasted too much time on you already.
>>13
Wow man, you're awesome. You went over everything I wanted you to go over. It's a shame I didn't know any of that stuff myself. Again, I've never taken a physics class before.
Thanks.
Name:
Anonymous2009-12-01 17:56
For the purposes of coding, either apply a force to the object equal to the object's mass times the gravitational constant you choose, or if you're merely looking for the acceleration, just change the velocity of said object in accordance with the gravitational constant. Remember: Force = Mass x Acceleration
Name:
Anonymous2009-12-02 4:59
>>15
I'm currently not going for realistic measurements. That will be the next step after I get the unrealistic: weight, mass, momentum, and etc... variables to work.
I'm more concerned about how I'm going to go about implementing Newton's 3rd law of motion. Let's say gravity was pushing an object down at a force of 9. Does that mean that the reaction/opposite force will also exert a force of 9 on the object?
Also, I'll never take Newton's name lightly anymore. Up until now I would always say to myself, "anybody could have invented those laws if they were born at that particular time (a time when so many new theories were being presented daily)." But now I realize the brilliance behind his laws.
Name:
Anonymous2009-12-02 9:31
Newton wasn't exactly the only one who proposed an inverse square gravitation force. He was just the first to solve the differential equations to show it fit the observed orbital data to the level of accuracy at the time.
Name:
Anonymous2009-12-02 20:56
>>16
avogadro's number
planck's constant
gravitational constant
phi
pi
those should be the only realistic (relatively accurate or locally accurate are better terms) measurements you need. Just write them down in you're preferred units (metric or FUCKYEAHAMERICA) once in a comment if need be and forget about it.
Does that mean that the reaction/opposite force will also exert a force of 9 on the object?
At static equilibrium, yes. During a collision, no. >>17
I think he's referring to the laws of motion.
Name:
Anonymous2009-12-04 13:44
>>19
>During a collision, no.
Details please. Which force has more power during the initial impact. And how are the forces dissolved into each other?
Name:
Anonymous2009-12-04 19:42
>>20
>Which force has more power during the initial impact.
The force from the ground, of course; after all, the falling object is losing its downward speed during the collision, which means it's accelerating upwards, which means that it has positive net force upwards.
>And how are the forces dissolved into each other?
What exactly do you mean here?
>>21
>What exactly do you mean here?
Disregard that. Your first sentence answered my question.
Thanks to the help I received in this thread, my platformer engine is now working. But it still needs a little more tweaking before it can be used to handle some of the stuff I plan on throwing at it. It's amazing how the progress of said platformer is directly correlated to my understanding of physics. If I wasn't such a masochist I would have suspended this project and caught up on my physics lessons.
On a semi-unrelated note, programming things is a lonely endeavor. Thank god for the Internet.
>>22
If you ever finish, let us know what the final product is.
Name:
Anonymous2009-12-15 4:15
gravity causes work
Name:
Anonymous2009-12-16 6:02
Christ on crutches, are you fucking serious, REALLY?
That was figured out Aeons ago!
For ever atomic particle (wave) there are repulsers called Neutrons and attractors called Electrons. Neutrons are part of the core which comprises a fraction of matter (mass), Electrons are part of the wave which contributes to how long the field of attraction will last by the amount of attraction and the stress of repulsion. Because each particle has this, the more particles there are, geometrically speaking, the more "Attraction and Repulsion" there is going to be.
For ever particle that makes up each human, each particle has a differing range of attraction and repulsion towards each interacting particle which is in contact with it, speaking in approximate proximity and "field contact."
Because the mass of the planet is great, the gravity field generated is great, but also, due to the gravity created by the mass the planet is being perpetually pulled towards its center while thermal activity created through frictive motion of increasing masses attempts to perpetually move outwards our planet shifts inwards while the field of gravity is at a rough constant with minor fluctuations due to new mass being added via asteroids and other debris from outside the planet. For each new atom within the planet's gravitational range, the gravity of the planet is affected as a whole...but only to the degree of the amount of mass introduced...which is roughly...insignificantly marginal.
This is what tells us why things can appear and remain separate at times, yet when put under stress, pressure or friction they seem to meld together.
You should see what happens when you impact basic asteroid elements and water at 2,000 mph...amino acids. :3