bool checkSurfaceCollision(const Vec& pos) {
    // Floor
    if (pos.z <= 0) return true;

    // Ceiling
    if (pos.z >= 2044) return true;

    // Side walls
    if (abs(pos.x) >= 4096) return true;

    // Back walls
    if (abs(pos.y) >= 5120) return true;

    // Simplified ramp check
    if (abs(pos.y) > 5120 - 1152) {
        float rampZ = (5120 - abs(pos.y)) * (642.775f / 1152.0f);
        if (pos.z <= rampZ) return true;
    }

    return false;
}

void RLBotBot::RenderTimeToSurface(const RLGSC::GameState& gs) {
   
    rlbot::ScopedRenderer renderer("time_to_surface_renderer");

    constexpr float MAX_PREDICTION_TIME = 6.0f;
    constexpr float TIME_STEP = 1.0f / 120.0f;
    constexpr float GRAVITY = -650.0f;

    // Get player position and velocity
    const PlayerData& player = gs.players[index];
    Vec pos = player.phys.pos;
    Vec vel = player.phys.vel;

    // Extrapolation variables
    float time = 0.0f;
    Vec extrapolatedPos = pos;
    Vec surfacePoint = pos;
    bool surfaceHit = false;

    // Extrapolate until we hit a surface or reach max time
    while (time < MAX_PREDICTION_TIME && !surfaceHit) {
        // Update position and velocity
        extrapolatedPos.x += vel.x * TIME_STEP;
        extrapolatedPos.y += vel.y * TIME_STEP;
        extrapolatedPos.z += vel.z * TIME_STEP + 0.5f * GRAVITY * TIME_STEP * TIME_STEP;
        vel.z += GRAVITY * TIME_STEP;

        // Check for collisions with surfaces
        if (checkSurfaceCollision(extrapolatedPos)) {
            surfacePoint = extrapolatedPos;
            surfaceHit = true;
        }
        else {
            time += TIME_STEP;
        }
    }

    // Define Rocket League colors
    rlbot::Color rocketLeagueBlue{ 0, 153, 255, 255 };
    rlbot::Color rocketLeagueOrange{ 235, 141, 31, 255 };
    rlbot::Color white{ 255, 255, 255, 255 };

    // Determine color based on player's team
    rlbot::Color playerColor = player.team == Team::BLUE ? rocketLeagueBlue : rocketLeagueOrange;

    // Render line from player to surface point
    rlbot::flat::Vector3 playerPos(
        static_cast<float>(pos.x),
        static_cast<float>(pos.y),
        static_cast<float>(pos.z)
    );
    rlbot::flat::Vector3 surfacePos(
        static_cast<float>(surfacePoint.x),
        static_cast<float>(surfacePoint.y),
        static_cast<float>(surfacePoint.z)
    );
    renderer.DrawLine3D(playerColor, playerPos, surfacePos);

    // Render time to surface (higher and white)
    std::stringstream timeSS;
    timeSS << std::fixed << std::setprecision(2) << time << "s";
    rlbot::flat::Vector3 textPos(
        surfacePos.x(),
        surfacePos.y(),
        surfacePos.z() + 100.0f  // Raise the text 100 units above the surface point
    );
    renderer.DrawString3D(timeSS.str(), white, textPos, 2.0f, 2.0f);  // Increased size for better visibility

    // Render information on screen
    std::stringstream infoSS;
    infoSS << "Time to surface: " << std::fixed << std::setprecision(2) << time << "s";
    renderer.DrawString2D(infoSS.str(), playerColor, rlbot::flat::Vector3(10, 10, 0), 2.0f, 2.0f);

    if (surfaceHit) {
        std::stringstream surfaceSS;
        surfaceSS << "Surface hit at: (" << std::fixed << std::setprecision(0)
            << surfacePoint.x << ", " << surfacePoint.y << ", " << surfacePoint.z << ")";
        renderer.DrawString2D(surfaceSS.str(), playerColor, rlbot::flat::Vector3(10, 40, 0), 2.0f, 2.0f);
    }
    else {
        renderer.DrawString2D("No surface hit within time limit", playerColor, rlbot::flat::Vector3(10, 40, 0), 2.0f, 2.0f);
    }
}
 fix this, when on a wal it thinks the closest exstraption point is the ground but thats false since there shouldent be calculated any exstrapolaiton if allready on a surface