I'm relatively new to games development and I have a 2D game where the playing area is an enclosed rectangle with width w and infinite height. In the playing area there is a ball. A gravity force of strength G acts on the ball. The ball starts at position p and has an initial velocity of v.
How would I calculate the position the ball will be at when it reaches the specified height h. I have a function setup using the following parameters:
bool CalculateXPositionAtHeight(float height, Vector2 position, Vector2 velocity, float Gravity, float width, float& xPosition);
- The playing area doesn’t have any boundary at the top, so no collision ever happens with it.
- The ball can be considered as a point.
- There are no precision issues and everything can easily fit in a float.
- There is no air resistance.
- All collisions are perfect without any energy loss.
- If the ball hits the bottom it won’t bounce.