with this 	static float DistToClosestWall(float x, float y) {
		float dist_side_wall = std::abs(4096.0f - std::abs(x));
		float dist_back_wall = std::abs(5120.0f - std::abs(y));

		// Corner calculation
		float x1 = 4096.0f - 1152.0f, y1 = 5120.0f, x2 = 4096.0f, y2 = 5120.0f - 1152.0f;
		float A = std::abs(x) - x1;
		float B = std::abs(y) - y1;
		float C = x2 - x1;
		float D = y2 - y1;

		float dot = A * C + B * D;
		float len_sq = C * C + D * D;
		float param = (len_sq != 0) ? dot / len_sq : -1;

		float xx, yy;
		if (param < 0) {
			xx = x1;
			yy = y1;
		}
		else if (param > 1) {
			xx = x2;
			yy = y2;
		}
		else {
			xx = x1 + param * C;
			yy = y1 + param * D;
		}

		float dx = std::abs(x) - xx;
		float dy = std::abs(y) - yy;
		float dist_corner_wall = std::sqrt(dx * dx + dy * dy);

		return std::min({ dist_side_wall, dist_back_wall, dist_corner_wall });
	}
}; improve this by adding an minimum time to walls calculation kinda how like this does but the example is really unoptimal static constexpr float SIDE_WALL_X = 4096.0f;
static constexpr float CLOSE_DISTANCE = 10.0f;
static constexpr float NEAR_WALL_DISTANCE = 4077.0f;
static constexpr float Z_THRESHOLD = 256.0f;
static constexpr float EPSILON = 1e-3f;
static constexpr float DIST_REACH_THRESH = 80.0f;
static constexpr float STEP_INTERVAL = 1.0f / 60.0f;
static constexpr float FLIP_FORCE = 495.0f;
static constexpr float AIR_ACCEL = 66.66667f;
static constexpr float BOOST_ACCEL_AIR = 1058.33333f;
static constexpr float MAX_TOTAL_SPEED = 2300.0f;
static constexpr float BRAKE_ACCEL = 3500.0f;
static constexpr float BOOST_ACCEL_GROUND = 991.66667f;
static constexpr float DRIVE_ACCEL = 1600.0f;
static constexpr float MAX_DRIVE_SPEED = 1410.0f;
static constexpr float GRAVITY_Z = -650.0f;
static constexpr float BACK_WALL_Y = 5120.0f;
static constexpr float NEG_BACK_WALL_Y = -5120.0f;
static constexpr float MAX_BACKWALL_Y = 5100.0f;
static constexpr float BOOST_ACCEL_POS = 1000.0f;
static constexpr float BOOST_ACCEL_NEG = -1000.0f;
static constexpr float FLOOR_Z = 18.0f;
static constexpr float BOOST_ACCEL_DOWN = -1000.0f;

static float calculateTimeToSideWalls(const PlayerData& player) {
	const Vec& pos = player.phys.pos;
	const Vec& vel = player.phys.vel;

	float minTime = std::numeric_limits<float>::infinity();

	if (std::abs(pos.x) >= NEAR_WALL_DISTANCE && std::abs(pos.x) <= SIDE_WALL_X) {
		return 0.0f;
	}

	if (vel.x > EPSILON) {
		float a = 0.5f * DRIVE_ACCEL;
		float b = vel.x;
		float c = pos.x - SIDE_WALL_X;

		float discriminant = b * b - 4.0f * a * c;

		if (discriminant >= 0.0f) {
			float sqrtD = std::sqrt(discriminant);
			float t1 = (-b + sqrtD) / (2.0f * a);
			float t2 = (-b - sqrtD) / (2.0f * a);

			if (t1 > EPSILON && t1 < minTime) {
				minTime = t1;
			}
			if (t2 > EPSILON && t2 < minTime) {
				minTime = t2;
			}
		}
	}

	if (vel.x < -EPSILON) {
		float a = 0.5f * (-DRIVE_ACCEL);
		float b = vel.x;
		float c = pos.x + SIDE_WALL_X;

		float discriminant = b * b - 4.0f * a * c;

		if (discriminant >= 0.0f) {
			float sqrtD = std::sqrt(discriminant);
			float t1 = (-b + sqrtD) / (2.0f * a);
			float t2 = (-b - sqrtD) / (2.0f * a);

			if (t1 > EPSILON && t1 < minTime) {
				minTime = t1;
			}
			if (t2 > EPSILON && t2 < minTime) {
				minTime = t2;
			}
		}
	}

	return minTime;
}

static float calculateTimeToBackWalls(const PlayerData& player) {
	const Vec& pos = player.phys.pos;
	const Vec& vel = player.phys.vel;

	float minTime = std::numeric_limits<float>::infinity();

	if (pos.y >= MAX_BACKWALL_Y || pos.y <= -MAX_BACKWALL_Y) {
		return 0.0f;
	}

	if (pos.y >= BACK_WALL_Y || pos.y <= NEG_BACK_WALL_Y) {
		return 0.0f;
	}

	if (vel.y > EPSILON) {
		float a = 0.5f * BOOST_ACCEL_POS;
		float b = vel.y;
		float c = pos.y - BACK_WALL_Y;

		float discriminant = b * b - 4.0f * a * c;

		if (discriminant >= 0.0f) {
			float sqrtD = std::sqrt(discriminant);
			float t1 = (-b + sqrtD) / (2.0f * a);
			float t2 = (-b - sqrtD) / (2.0f * a);

			if (t1 > EPSILON && t1 < minTime) {
				minTime = t1;
			}
			if (t2 > EPSILON && t2 < minTime) {
				minTime = t2;
			}
		}
	}

	if (vel.y < -EPSILON) {
		float a = 0.5f * BOOST_ACCEL_NEG;
		float b = vel.y;
		float c = pos.y - NEG_BACK_WALL_Y;

		float discriminant = b * b - 4.0f * a * c;

		if (discriminant >= 0.0f) {
			float sqrtD = std::sqrt(discriminant);
			float t1 = (-b + sqrtD) / (2.0f * a);
			float t2 = (-b - sqrtD) / (2.0f * a);

			if (t1 > EPSILON && t1 < minTime) {
				minTime = t1;
			}
			if (t2 > EPSILON && t2 < minTime) {
				minTime = t2;
			}
		}
	}

	return minTime;
}

static float calculateTimeToFloor(const PlayerData& player) {
	const Vec& pos = player.phys.pos;
	const Vec& vel = player.phys.vel;

	if (pos.z <= FLOOR_Z) {
		return 0.0f;
	}

	float totalAccel = GRAVITY_Z + BOOST_ACCEL_DOWN;

	float a = 0.5f * totalAccel;
	float b = vel.z;
	float c = pos.z - FLOOR_Z;

	float discriminant = b * b - 4.0f * a * c;

	if (discriminant < 0.0f) {
		return std::numeric_limits<float>::infinity();
	}

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

	float timeToFloor = std::numeric_limits<float>::infinity();

	if (t1 > 0.0f) {
		timeToFloor = t1;
	}
	if (t2 > 0.0f && t2 < timeToFloor) {
		timeToFloor = t2;
	}

	return timeToFloor;
} kinda try to assume the player is going as fast as possible to the closest wall	Vec carPos = player.phys.pos;
	Vec carVel = player.phys.vel;
	Vec dirToTarget = (targetPos - carPos).Normalized();
	float dist = (targetPos - carPos).Length() - CommonValues::BALL_RADIUS;
	float vel = carVel.Dot(dirToTarget);
	float rotTime = calculateRotationTime(player, targetPos);
	float timeToSurface = calculateTimeToReachAnySurface(player);

	float t = 0;
	for (float curDist = dist, curVel = vel; curDist > DIST_REACH_THRESH; t += STEP_INTERVAL, curDist -= curVel * STEP_INTERVAL) {
		bool hasRotated = t >= rotTime;
		bool onSurface = t >= timeToSurface;

		if (curVel < MAX_TOTAL_SPEED && t == 0) {
			// Flip force
			curVel += FLIP_FORCE;
		}

		if (onSurface) {
			if (curVel < 0) {
				curVel += (BRAKE_ACCEL + BOOST_ACCEL_GROUND * hasRotated) * STEP_INTERVAL;
			}
			else if (curVel < MAX_DRIVE_SPEED) {
				curVel += (DRIVE_ACCEL + BOOST_ACCEL_GROUND * hasRotated) * STEP_INTERVAL;
			}
			else if (curVel < MAX_TOTAL_SPEED) {
				curVel += BOOST_ACCEL_GROUND * hasRotated * STEP_INTERVAL;
			}
		}

		if (curVel >= MAX_TOTAL_SPEED) {
			return t + (curDist / curVel);
		}
	}
	return t;
} the closest wall is also maybe the wall the player has velocity towards, do an extraption calculation to figure this out