why isnt this working its not outputting anything class SimpleTimeToReachCalculator {…
- User
why isnt this working its not outputting anything class SimpleTimeToReachCalculator { public: static float calculateTimeToReach(float xyDist, float zDist, float velToTarget, float rotTime, float surfaceTime) { float dist = std::sqrt(xyDist * xyDist + zDist * zDist); float vel = velToTarget;
// Determine whether to use aerial acceleration float aerialTime = 0; float aerialDist = dist; float aerialVel = vel; while (aerialDist > DIST_REACH_THRESH && aerialTime < surfaceTime) { aerialVel += (AIR_ACCEL + BOOST_ACCEL_AIR) * STEP_INTERVAL; if (aerialVel > MAX_TOTAL_SPEED) aerialVel = MAX_TOTAL_SPEED; aerialDist -= aerialVel * STEP_INTERVAL; aerialTime += STEP_INTERVAL; } bool useAerial = aerialTime < surfaceTime; float t = 0; for (float curDist = dist, curVel = vel; curDist > DIST_REACH_THRESH; t += STEP_INTERVAL, curDist -= curVel * STEP_INTERVAL) { bool hasRotated = t >= rotTime; if (curVel < MAX_TOTAL_SPEED && t == 0) { // Flip force curVel += FLIP_FORCE; } if (useAerial) { // Aerial acceleration if (curVel < MAX_DRIVE_SPEED) { curVel += (AIR_ACCEL + BOOST_ACCEL_AIR * hasRotated) * STEP_INTERVAL; } else if (curVel < MAX_TOTAL_SPEED) { curVel += BOOST_ACCEL_AIR * hasRotated * STEP_INTERVAL; } } else { // Ground acceleration 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 / MAX_TOTAL_SPEED); } } return t; } static float calculateTimeToReach(const PlayerData& player, const Vec& targetPos) { Vec deltaPos = targetPos - player.phys.pos; float xyDist = deltaPos.To2D().Length(); float zDist = std::abs(deltaPos.z); float velToTarget = player.phys.vel.Dot(deltaPos.Normalized()); float rotTime = calculateRotationTime(player, targetPos); float surfaceTime = calculateTimeToReachAnySurface(player); return calculateTimeToReach(xyDist, zDist, velToTarget, rotTime, surfaceTime); } static float calculateRotationTime(const PlayerData& player, const Vec& targetPos) { constexpr float MAX_ANG_VEL = 5.5f * 0.9f; Vec playerForward = player.phys.rotMat.forward; Vec dirToTarget = (targetPos - player.phys.pos).Normalized(); float dotProduct = RS_CLAMP(playerForward.Dot(dirToTarget), -1.0f, 1.0f); float angleDiff = std::acos(dotProduct); return angleDiff / MAX_ANG_VEL; } static float calculateTimeToReachAnySurface(const PlayerData& player) { float timeToSideWalls = calculateTimeToSideWalls(player); float timeToBackWalls = calculateTimeToBackWalls(player); float timeToFloor = calculateTimeToFloor(player); float minTimeBetweenBackWallsAndFloor = RS_MIN(timeToBackWalls, timeToFloor); float minTime = RS_MIN(timeToSideWalls, minTimeBetweenBackWallsAndFloor); return minTime; }private: 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 MAX_DRIVE_SPEED = 1410.0f;
- Assistant