Hi, I have been looking at many posts, but none of them really explain what I want to know.
I want to create a "gravity ball" game for practice with gravity so that I can later implement it into my game.
The game consists in a ball dropping with gravity, and you having to click it to push it back up again.
I am not yet concerned with sideways movement as I'd have to calculate angles and stuff, and I only want to focus on gravity itself now.
I have coded this as a gravity function:
acceleration += 9.8; velocity += acceleration; y += velocity;
I have however, a series of conceptual problems as I do not truly understand the gravity equation. The following are my questions:
Acceleration is measured as ms^-2, so I would only have to compute this equation every second. This would then make my game change velocity every second and therefore would give an non-smooth effect. How would I go about computing this equation 60 times per second? I think there is an equation for gravity involving time as time an acceleration are related, is there such a thing?
Another thing I can't get my head around is how gravity works when the object is moving upwards. If the downward speed is of, say, 50m/s, and we exert a force that makes it have an upwards speed of 100m/s, how does the formula create the parabola effect needed? Do you reset the timer and the acceleration inside the gravity equation, so that the first second its going upwards it gets a velocity of 90 m/s, and then its velocity keeps decreasing till it flips around and starts falling again? When do I reset the timer?
Please explain how it works, or give me an example of the code used for such an exercise.