FS
something is wrong since if im not directly facing a wal it says the car isnt going towars a surface all the time witch is wrong it shouldent matter what way the car is facing only the direction the car is heaing ig


You're absolutely right, and I apologize for the oversight. The issue is that we're not considering the car's actual velocity vector, but rather its forward direction. Let's fix this by using the car's actual velocity for prediction. Here's the corrected version:

cpp

Copy
void RLBotBot::timewallexsrap(const RLGSC::GameState& gs) {
    rlbot::ScopedRenderer renderer("time_to_reach_renderer");

    // Field dimensions
    const float FIELD_LENGTH = 5120.0f;
    const float FIELD_WIDTH = 4096.0f;
    const float FIELD_HEIGHT = 2044.0f;
    const float MIN_VELOCITY_THRESHOLD = 1.0f;

    // Ramp dimensions
    const float RAMP_HEIGHT = 256.0f;
    const float SIDE_WALL_RAMP_WIDTH = 1024.0f;
    const float BACK_WALL_RAMP_WIDTH = 1024.0f;

    if (index >= gs.players.size()) {
        std::cerr << "Invalid player index: " << index << std::endl;
        return;
    }

    const auto& car = gs.players[index];
    Vec carPos = car.phys.pos;
    Vec carVel = car.phys.vel;  // Use actual velocity instead of forward direction
    Vec carUp = car.phys.rotMat.up;
    Vec gravity(0, 0, -650); // Rocket League's gravity

    const float SURFACE_DISTANCE_THRESHOLD = 5.0f;
    const float SURFACE_ANGLE_THRESHOLD = 0.1f;

    auto isOnSurface = [SURFACE_DISTANCE_THRESHOLD, SURFACE_ANGLE_THRESHOLD](const Vec& pos, const Vec& up, const Vec& normal, float planeD) {
        float distance = std::abs(pos.Dot(normal) + planeD);
        float alignment = std::abs(up.Dot(normal));
        return distance < SURFACE_DISTANCE_THRESHOLD && alignment > (1 - SURFACE_ANGLE_THRESHOLD);
    };

    auto checkCollision = [MIN_VELOCITY_THRESHOLD, gravity, isOnSurface](const Vec& pos, const Vec& vel, const Vec& up, const Vec& planeNormal, float planeD) {
        if (isOnSurface(pos, up, planeNormal, planeD)) {
            return std::make_pair(0.0f, pos);
        }

        // Quadratic equation coefficients
        float a = 0.5f * gravity.Dot(planeNormal);
        float b = vel.Dot(planeNormal);
        float c = pos.Dot(planeNormal) + planeD;

        // Solve quadratic equation
        float discriminant = b * b - 4 * a * c;
        if (discriminant < 0) {
            return std::make_pair(std::numeric_limits<float>::infinity(), Vec());
        }

        float t1 = (-b + std::sqrt(discriminant)) / (2 * a);
        float t2 = (-b - std::sqrt(discriminant)) / (2 * a);

        float t = (t1 > 0 && t1 < t2) ? t1 : t2;
        if (t < 0) {
            return std::make_pair(std::numeric_limits<float>::infinity(), Vec());
        }

        Vec collisionPos = pos + (vel * t) + (gravity * (0.5f * t * t));
        return std::make_pair(t, collisionPos);
    };

    std::vector<std::pair<Vec, float>> planes;

    // Main surfaces
    planes.push_back({{1, 0, 0}, -FIELD_WIDTH});   // Right wall
    planes.push_back({{-1, 0, 0}, -FIELD_WIDTH});  // Left wall
    planes.push_back({{0, 1, 0}, -FIELD_LENGTH});  // Back blue wall
    planes.push_back({{0, -1, 0}, -FIELD_LENGTH}); // Back orange wall
    planes.push_back({{0, 0, 1}, 0});              // Floor
    planes.push_back({{0, 0, -1}, FIELD_HEIGHT});  // Ceiling

    // Side wall ramps
    float sideRampAngle = std::atan2(RAMP_HEIGHT, SIDE_WALL_RAMP_WIDTH);
    Vec sideRampNormal = Vec(std::cos(sideRampAngle), 0, std::sin(sideRampAngle)).Normalized();
    planes.push_back({sideRampNormal, -FIELD_WIDTH});
    planes.push_back({sideRampNormal * Vec(-1, 1, 1), -FIELD_WIDTH});

    // Back wall ramps
    float backRampAngle = std::atan2(RAMP_HEIGHT, BACK_WALL_RAMP_WIDTH);
    Vec backRampNormal = Vec(0, std::cos(backRampAngle), std::sin(backRampAngle)).Normalized();
    planes.push_back({backRampNormal, -FIELD_LENGTH});
    planes.push_back({backRampNormal * Vec(1, -1, 1), -FIELD_LENGTH});

    // Corner ramps (45-degree approximation)
    Vec cornerRampNormal = Vec(1, 1, 1).Normalized();
    float cornerOffset = -std::sqrt(2) * (FIELD_WIDTH + FIELD_LENGTH - BACK_WALL_RAMP_WIDTH) / 2;
    planes.push_back({cornerRampNormal, cornerOffset});
    planes.push_back({cornerRampNormal * Vec(-1, 1, 1), cornerOffset});
    planes.push_back({cornerRampNormal * Vec(1, -1, 1), cornerOffset});
    planes.push_back({cornerRampNormal * Vec(-1, -1, 1), cornerOffset});

    float earliestTime = std::numeric_limits<float>::infinity();
    Vec collisionPoint;
    Vec collisionNormal;
    bool isCurrentlyOnSurface = false;

    for (const auto& plane : planes) {
        auto [time, point] = checkCollision(carPos, carVel, carUp, plane.first, plane.second);
        if (time == 0) {
            isCurrentlyOnSurface = true;
            collisionPoint = carPos;
            collisionNormal = plane.first;
            break;
        }
        if (time > 0 && time < earliestTime) {
            // Check if the collision point is within the field boundaries
            if (std::abs(point.x) <= FIELD_WIDTH &&
                std::abs(point.y) <= FIELD_LENGTH &&
                point.z >= 0 && point.z <= FIELD_HEIGHT) {
                earliestTime = time;
                collisionPoint = point;
                collisionNormal = plane.first;
            }
        }
    }

    if (isCurrentlyOnSurface) {
        std::cout << "Car is currently on a surface." << std::endl;
    }
    else if (earliestTime == std::numeric_limits<float>::infinity()) {
        std::cout << "Car is not moving towards any surface." << std::endl;
        return;
    }

    // Rendering
    rlbot::flat::Vector3 carVector = {carPos.x, carPos.y, carPos.z};
    rlbot::flat::Vector3 collisionVector = {collisionPoint.x, collisionPoint.y, collisionPoint.z};

    rlbot::Color lineColor(255, 255, 0, 255);
    renderer.DrawLine3D(lineColor, carVector, collisionVector);

    rlbot::Color markerColor(255, 0, 0, 255);
    float markerSize = 50.0f;
    renderer.DrawRect3D(markerColor, collisionVector, static_cast<int>(markerSize), static_cast<int>(markerSize), true, true);

    rlbot::Color textColor(255, 255, 255, 255);
    std::string surfaceInfo = earliestTime == 0 ?
        "On surface" :
        "Time to collision: " + std::to_string(earliestTime);
    rlbot::flat::Vector3 textPosition = {carPos.x, carPos.y + 100.0f, carPos.z};
    renderer.DrawString3D(surfaceInfo, textColor, textPosition, 1, 1);

    // Draw normal vector at collision point
    rlbot::flat::Vector3 normalEnd = {
        collisionPoint.x + collisionNormal.x * 100,
        collisionPoint.y + collisionNormal.y * 100,
        collisionPoint.z + collisionNormal.z * 100
    };
    rlbot::Color normalColor(0, 255, 0, 255);
    renderer.DrawLine3D(normalColor, collisionVector, normalEnd);
} fix the math and logic on this too correctly calculate the landing point of the player too the walls ceiling and florr and kinda hard but the ramps between all the surfaces, the ramps height is 256 witch is the only info you got lol, so do exstrapolation calcualtion to calculate the landing point then render it too rlbot