remake this to only be one function since this seems pretty redundant for no reaosn…
- User
remake this to only be one function since this seems pretty redundant for no reaosn 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 = 133.334f; static constexpr float BOOST_ACCEL_AIR = 2116.666f; static constexpr float MAX_TOTAL_SPEED = 2300.0f; static constexpr float BRAKE_ACCEL = 3500.0f; static constexpr float BOOST_ACCEL_GROUND = 1983.332f; 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 constexpr float MAX_TIME = 10.0f; static constexpr float JUMP_IMPULSE = 291.667f; static constexpr float GROUND_Z_THRESHOLD = 50.0f; static constexpr float MAX_SIMULATION_TIME = 10.0f;
static float calculateTimeToSideWalls(const PlayerData& player) { const Vec& pos = player.phys.pos; const Vec& vel = player.phys.vel;
codefloat 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; - Assistant