Calculating the future position of a ball that can bounce off walls

I am trying to make some future prediction where I want to calculate where the ball should be of a certain height (y). The ball shoots up and can bounce off the sides of the game. Bounces do not affect speed.

My current configuration is lower left (0,0), and lower right (10,0) without upper height limit.

the code:

void getPositionXAtHeight(float height, Vec2 pos, Vec2 vel, float gravityForce = 9.8f, float gameWidth, float& positionX)
{
    float a = gravityForce / 2.0f;
    float b = vel.y;
    float c = pos.y - height;

    float t = (sqrtf((b * b) - (4.0f * a * c)) - b) / (2.0f * a);

    positionX = pos.x + (vel.x*t);
}

Idea

Can someone tell me if my code is really correct and what should I do to deal with sloping walls? I also feel that I have to do some error checking, but I'm not sure where I need it?

+4
source share
1 answer

, , , y. , , "" x, 10. . x = 11, x = 9 (10 - (11 - 10)). " " ..

+1

Source: https://habr.com/ru/post/1659340/


All Articles