add a function in here that prints out the current break accel class…
- User
add a function in here that prints out the current break accel class TimeToReachCalculatorv2 { public: static float calculateTimeToReach(const PlayerData& player, const Vec& targetPos) { // Extract position and velocity Vec carPos = player.phys.pos; Vec carVel = player.phys.vel;
// Calculate direction and distance to target Vec targetVector = targetPos - carPos; float initialDist = targetVector.Length() - CommonValues::BALL_RADIUS; float dist = RS_MAX(initialDist, 0.0f); // Prevent negative distances // Normalize direction Vec dirToTarget = (dist > 0.0f) ? targetVector.Normalized() : Vec{ 0.0f, 0.0f, 0.0f }; // Velocity towards target float vel = carVel.Dot(dirToTarget); // Calculate rotation and surface times float rotTime = calculateRotationTime(player, targetPos); float timeToSurface = calculateTimeToReachAnySurface(player); // Time to land on the ground // If already within threshold, return 0 if (dist <= DIST_REACH_THRESH) { return 0.0f; } // -------------------- // Time to Reach in Air Only // -------------------- float timeInAir = 0.0f; float curDistAir = dist; float curVelAir = vel; bool hasAppliedFlipAir = false; while (curDistAir > DIST_REACH_THRESH && timeInAir < FLT_MAX) { bool hasRotated = timeInAir >= rotTime; // Apply initial Flip Force once if (!hasAppliedFlipAir && curVelAir < MAX_TOTAL_SPEED) { curVelAir += FLIP_FORCE; hasAppliedFlipAir = true; } // Apply air-based accelerations if (curVelAir < 0.0f) { // Braking in air curVelAir += (AIR_ACCEL + BOOST_ACCEL_AIR * hasRotated) * STEP_INTERVAL; } else if (curVelAir < MAX_TOTAL_SPEED) { // Boosting in air curVelAir += (BOOST_ACCEL_AIR * hasRotated) * STEP_INTERVAL; } // Clamp velocity curVelAir = RS_CLAMP(curVelAir, 0.0f, MAX_TOTAL_SPEED); // Calculate potential distance covered in this step float potentialMove = curVelAir * STEP_INTERVAL; if (potentialMove >= (curDistAir - DIST_REACH_THRESH)) { // Calculate the exact time needed for the remaining distance float remainingDist = curDistAir - DIST_REACH_THRESH; if (curVelAir > 0.0f) { float partialStep = remainingDist / curVelAir; timeInAir += partialStep; } else { // Cannot reach the target with zero velocity timeInAir = FLT_MAX; } break; } else { // Normal step timeInAir += STEP_INTERVAL; curDistAir -= potentialMove; } } // -------------------- // Time to Reach on Ground After Landing // -------------------- float timeOnGround = 0.0f; float curDistGround = dist; float curVelGround = vel; bool hasAppliedFlipGround = false; while (curDistGround > DIST_REACH_THRESH && timeOnGround < FLT_MAX) { bool hasRotated = timeOnGround >= rotTime; // Apply initial Flip Force once if (!hasAppliedFlipGround && curVelGround < MAX_TOTAL_SPEED) { curVelGround += FLIP_FORCE; hasAppliedFlipGround = true; } // Apply ground-based accelerations if (curVelGround < 0.0f) { // Braking on ground curVelGround += (BRAKE_ACCEL + BOOST_ACCEL_GROUND * hasRotated) * STEP_INTERVAL; } else if (curVelGround < MAX_DRIVE_SPEED) { // Driving on ground curVelGround += (DRIVE_ACCEL + BOOST_ACCEL_GROUND * hasRotated) * STEP_INTERVAL; } else if (curVelGround < MAX_TOTAL_SPEED) { // Boosting on ground curVelGround += (BOOST_ACCEL_GROUND * hasRotated) * STEP_INTERVAL; } // Clamp velocity curVelGround = RS_CLAMP(curVelGround, 0.0f, MAX_TOTAL_SPEED); // Calculate potential distance covered in this step float potentialMove = curVelGround * STEP_INTERVAL; if (potentialMove >= (curDistGround - DIST_REACH_THRESH)) { // Calculate the exact time needed for the remaining distance float remainingDist = curDistGround - DIST_REACH_THRESH; if (curVelGround > 0.0f) { float partialStep = remainingDist / curVelGround; timeOnGround += partialStep; } else { // Cannot reach the target with zero velocity timeOnGround = FLT_MAX; } break; } else { // Normal step timeOnGround += STEP_INTERVAL; curDistGround -= potentialMove; } } // -------------------- // Final Time Calculation // -------------------- float totalAirTime = timeInAir; float totalGroundTime = timeToSurface + timeOnGround; // Handle invalid paths if (totalAirTime == FLT_MAX && totalGroundTime == FLT_MAX) { return FLT_MAX; // Indicate failure to reach the target } if (totalAirTime == FLT_MAX) { return totalGroundTime; } if (totalGroundTime == FLT_MAX) { return totalAirTime; } // Return the minimum of the two times return RS_MIN(totalAirTime, totalGroundTime); } - Assistant