A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartMove.cc
Go to the documentation of this file.
1#include "KartMove.hh"
2
11
15
17#include "game/item/KartItem.hh"
18
23
24#include <egg/math/Math.hh>
25#include <egg/math/Quat.hh>
26
27namespace Kinoko::Kart {
28
35
36static constexpr std::array<CannonParameter, 3> CANNON_PARAMETERS = {{
37 {500.0f, 0.0f, 6000.0f, -1.0f},
38 {500.0f, 5000.0f, 6000.0f, -1.0f},
39 {120.0f, 2000.0f, 1000.0f, 45.0f},
40}};
41
43KartMove::KartMove() : m_smoothedUp(EGG::Vector3f::ey), m_scale(1.0f, 1.0f, 1.0f) {
44 m_totalScale = 1.0f;
45 m_hitboxScale = 1.0f;
47 m_invScale = 1.0f;
50 m_jump = nullptr;
51
52 // The base game doesn't initialize this explicitly, since EGG::Heaps are memset to 0.
53 // KartSub::initAABB reads it before KartSub::resetPhysics calls setKartSpeedLimit.
54 // The AABB will get resized later in KartSub::resetPhysics, but we initialize here for
55 // posterity's sake.
56 m_hardSpeedLimit = 0.0f;
57}
58
65
72
77 m_realTurn = 0.0f;
78 m_rawTurn = 0.0f;
79
81
84 return;
85 }
86
88 return;
89 }
90
92 m_rawTurn = -state()->stickX();
94 m_rawTurn *= 0.35f;
96 m_rawTurn *= 0.01f;
97 }
98 } else {
99 m_rawTurn = static_cast<f32>(m_hopStickX);
100 }
101
102 f32 reactivity;
103 if (state()->isDrifting()) {
104 reactivity = param()->stats().driftReactivity;
105 } else {
106 reactivity = param()->stats().handlingReactivity;
107 }
108
109 m_weightedTurn = m_rawTurn * reactivity + m_weightedTurn * (1.0f - reactivity);
110 m_weightedTurn = std::clamp(m_weightedTurn, -1.0f, 1.0f);
111
113
114 if (!state()->isDrifting()) {
115 return;
116 }
117
118 m_realTurn = (m_weightedTurn + static_cast<f32>(m_hopStickX)) * 0.5f;
119 m_realTurn = m_realTurn * 0.8f + 0.2f * static_cast<f32>(m_hopStickX);
120 m_realTurn = std::clamp(m_realTurn, -1.0f, 1.0f);
121}
122
125 static constexpr std::array<DriftingParameters, 3> DRIFTING_PARAMS_ARRAY = {{
126 {10.0f, 0.5f, 0.5f, 1.0f},
127 {10.0f, 0.5f, 0.5f, 0.2f},
128 {10.0f, 0.22f, 0.5f, 0.2f},
129 }};
130
131 init(false, false);
132 m_dir = bodyFront();
138 m_driftingParams = &DRIFTING_PARAMS_ARRAY[static_cast<u32>(param()->stats().driftType)];
140}
141
143void KartMove::init(bool b1, bool b2) {
144 m_lastSpeed = 0.0f;
147 m_speed = 0.0f;
149 m_acceleration = 0.0f;
159 m_hasLandingDir = false;
160 m_outsideDriftAngle = 0.0f;
161 m_landingAngle = 0.0f;
163 m_speedRatio = 0.0f;
164 m_speedRatioCapped = 0.0f;
165 m_kclSpeedFactor = 1.0f;
166 m_kclRotFactor = 1.0f;
168 m_kclWheelRotFactor = 1.0f;
169
170 if (!b2) {
172 }
173
174 m_hopStickX = 0;
175 m_hopFrame = 0;
178 m_divingRot = 0.0f;
181 m_smtCharge = 0;
182 m_mtCharge = 0;
183 m_outsideDriftBonus = 0.0f;
184 m_boost.reset();
187 m_reject.reset();
189 m_ssmtCharge = 0;
193 m_realTurn = 0.0f;
194 m_weightedTurn = 0.0f;
195
196 if (!b1) {
197 m_scale.set(1.0f);
198 m_totalScale = 1.0f;
199 m_hitboxScale = 1.0f;
201 m_invScale = 1.0f;
203 m_shockTimer = 0;
204 m_crushTimer = 0;
205 }
206
207 m_jumpPadMinSpeed = 0.0f;
208 m_jumpPadMaxSpeed = 0.0f;
210 m_jumpPadProperties = nullptr;
211 m_rampBoost = 0;
212 m_autoDriftAngle = 0.0f;
214
220
221 m_hopVelY = 0.0f;
222 m_hopPosY = 0.0f;
223 m_hopGravity = 0.0f;
224 m_timeInRespawn = 0;
227 m_respawnTimer = 0;
228 m_bumpTimer = 0;
232 m_jump->reset();
233 m_halfPipe->reset();
234 m_rawTurn = 0.0f;
235}
236
255
259 EGG::Quatf quaternion = EGG::Quatf::FromRPY(angles * DEG2RAD);
260 EGG::Vector3f newPos = position;
262 Field::KCLTypeMask kcl_flags = KCL_NONE;
263
264 bool bColliding = Field::CollisionDirector::Instance()->checkSphereFullPush(100.0f, newPos,
265 EGG::Vector3f::inf, KCL_ANY, &info, &kcl_flags, 0);
266
267 if (bColliding && (kcl_flags & KCL_TYPE_FLOOR)) {
268 newPos = newPos + info.tangentOff + (info.floorNrm * -100.0f);
269 newPos += info.floorNrm * bsp().initialYPos;
270 }
271
272 setPos(newPos);
273 setRot(quaternion);
274
276
277 physics()->setPos(pos());
279
281 m_dir = bodyFront();
283 m_up = bodyUp();
284 dynamics()->setTop(m_up);
285
286 for (u16 tireIdx = 0; tireIdx < suspCount(); ++tireIdx) {
287 suspension(tireIdx)->setInitialState();
288 }
289}
290
298
301 return;
302 }
303
305 m_burnout.calc();
307 m_halfPipe->calc();
308 calcTop();
312 m_jump->calc();
313
314 m_bumpTimer = std::max(m_bumpTimer - 1, 0);
315
317 calcDirs();
319 calcOffroad();
320 calcTurn();
321
324 }
325
326 calcWheelie();
327 calcSsmt();
328 calcBoost();
331 calcShock();
332 calcCrushed();
333 calcScale();
334
336 calcCannon();
337 }
338
342 calcRotation();
343}
344
347 constexpr float RESPAWN_HEIGHT = 700.0f;
348
349 const auto *jugemPoint = System::RaceManager::Instance()->jugemPoint();
350 const EGG::Vector3f &jugemPos = jugemPoint->pos();
351 const EGG::Vector3f &jugemRot = jugemPoint->rot();
352
353 EGG::Vector3f respawnPos = jugemPos;
354 respawnPos.y += RESPAWN_HEIGHT;
355 EGG::Vector3f respawnRot = EGG::Vector3f(0.0f, jugemRot.y, 0.0f);
356
357 setInitialPhysicsValues(respawnPos, respawnRot);
358
360
362}
363
366 constexpr f32 LAKITU_VELOCITY = 1.5f;
367 constexpr u16 RESPAWN_DURATION = 110;
368
370
372 return;
373 }
374
375 EGG::Vector3f newPos = pos();
376 newPos.y -= LAKITU_VELOCITY;
377 dynamics()->setPos(newPos);
378 dynamics()->setNoGravity(true);
379
380 if (++m_timeInRespawn > RESPAWN_DURATION) {
382 m_timeInRespawn = 0;
384 dynamics()->setNoGravity(false);
385 }
386}
387
390 constexpr s16 RESPAWN_BOOST_DURATION = 30;
391 constexpr s16 RESPAWN_BOOST_INPUT_LENIENCY = 4;
392
394
397 if (m_respawnPreLandTimer > 0) {
399 activateBoost(KartBoost::Type::AllMt, RESPAWN_BOOST_DURATION);
400 m_respawnTimer = RESPAWN_BOOST_DURATION;
401 }
402 } else {
403 m_respawnPostLandTimer = RESPAWN_BOOST_INPUT_LENIENCY;
404 }
405
408 }
409
411
413 m_respawnPreLandTimer = RESPAWN_BOOST_INPUT_LENIENCY;
415 }
416 } else {
417 if (m_respawnPostLandTimer > 0) {
420 activateBoost(KartBoost::Type::AllMt, RESPAWN_BOOST_DURATION);
421 m_respawnTimer = RESPAWN_BOOST_DURATION;
422 }
423
425 }
426
428 } else {
430 }
431 }
432
433 m_respawnTimer = std::max(0, m_respawnTimer - 1);
434}
435
438 f32 stabilizationFactor = 0.1f;
439 m_hasLandingDir = false;
440 EGG::Vector3f inputTop = state()->top();
442
444 m_smoothedUp = inputTop;
445 m_up = inputTop;
448 m_hasLandingDir = true;
449 } else {
450 if (status.onBit(eStatus::Hop) && m_hopPosY > 0.0f) {
451 stabilizationFactor = m_driftingParams->stabilizationFactor;
453 if ((m_flags.onBit(eFlags::TrickableSurface) || state()->trickableTimer() > 0) &&
454 inputTop.dot(m_dir) > 0.0f && m_speed > 50.0f &&
455 collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::NotTrickable)) {
456 inputTop = m_up;
457 } else {
458 m_up = inputTop;
459 }
460
461 f32 scalar = 0.8f;
462
467 f32 topDotZ = 0.8f - 6.0f * (EGG::Mathf::abs(inputTop.dot(componentZAxis())));
468 scalar = std::clamp(topDotZ, 0.3f, 0.8f);
469 }
470
471 m_smoothedUp += (inputTop - m_smoothedUp) * scalar;
473
474 f32 bodyDotFront = bodyFront().dot(m_smoothedUp);
475
476 if (bodyDotFront < -0.1f) {
477 stabilizationFactor += std::min(0.2f, EGG::Mathf::abs(bodyDotFront) * 0.5f);
478 }
479
480 if (collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::BoostRamp)) {
481 stabilizationFactor = 0.4f;
482 }
483 } else {
485 }
486 }
487
488 dynamics()->setStabilizationFactor(stabilizationFactor);
489
493}
494
499
501 return;
502 }
503
504 if (m_smoothedUp.y <= 0.99f) {
507 } else {
509 }
510
511 if (m_up.y <= 0.99f) {
512 m_up += (EGG::Vector3f::ey - m_up) * 0.03f;
513 m_up.normalise();
514 } else {
516 }
517}
518
523 const auto *raceMgr = System::RaceManager::Instance();
524 if (!raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
525 return;
526 }
527
530 }
531
534 }
535
538 }
539
541}
542
546 EGG::Vector3f local_88 = right.cross(m_smoothedUp);
547 local_88.normalise();
550
554 status.offBit(eStatus::JumpPad) && state()->airtime() <= 5) ||
557 EGG::Vector3f local_94 = local_88;
559 local_94 = m_hopDir;
560 }
561
562 EGG::Matrix34f mat;
565 EGG::Vector3f local_b8 = mat.multVector(local_94);
566 local_b8 = local_b8.perpInPlane(m_smoothedUp, true);
567
568 EGG::Vector3f dirDiff = local_b8 - m_dir;
569
570 if (dirDiff.squaredLength() <= std::numeric_limits<f32>::epsilon()) {
571 m_dir = local_b8;
573 } else {
574 EGG::Vector3f origDirCross = m_dir.cross(local_b8);
575 m_dirDiff += m_kclRotFactor * dirDiff;
576 m_dir += m_dirDiff;
578 m_dirDiff *= 0.1f;
579 EGG::Vector3f newDirCross = m_dir.cross(local_b8);
580
581 if (origDirCross.dot(newDirCross) < 0.0f) {
582 m_dir = local_b8;
584 }
585 }
586
589 } else {
591 }
592
595 }
596
597 EGG::Vector3f nextDir = m_up.cross(local_88);
598 m_smoothedForward = nextDir.cross(m_up);
600
601 if (m_hasLandingDir) {
602 f32 dot = m_dir.dot(m_landingDir);
604 f32 crossDot = cross.length();
605 f32 angle = EGG::Mathf::atan2(crossDot, dot);
606 angle = EGG::Mathf::abs(angle);
607
608 f32 fVar4 = 1.0f;
609 if (cross.dot(m_smoothedUp) < 0.0f) {
610 fVar4 = -1.0f;
611 }
612
613 m_landingAngle += (angle * RAD2DEG) * fVar4;
614 }
615
616 if (m_landingAngle <= 0.0f) {
617 if (m_landingAngle < 0.0f) {
618 m_landingAngle = std::min(0.0f, m_landingAngle + 2.0f);
619 }
620 } else {
621 m_landingAngle = std::max(0.0f, m_landingAngle - 2.0f);
622 }
623}
624
627 constexpr f32 STICKY_RADIUS = 200.0f;
628 constexpr Field::KCLTypeMask STICKY_MASK =
630
632
635 return;
636 }
637
639 collide()->surfaceFlags().offBit(KartCollide::eSurfaceFlags::Trickable)) ||
640 EGG::Mathf::abs(m_speed) <= 20.0f) {
641 return;
642 }
643
646 Field::CollisionInfo colInfo;
647 colInfo.bbox.setZero();
648 Field::KCLTypeMask kcl_flags = KCL_NONE;
649 bool stickyRoad = false;
650
651 for (size_t i = 0; i < 3; ++i) {
652 EGG::Vector3f newPos = pos + vel;
653 if (Field::CollisionDirector::Instance()->checkSphereFull(STICKY_RADIUS, newPos,
654 EGG::Vector3f::inf, STICKY_MASK, &colInfo, &kcl_flags, 0)) {
655 m_vel1Dir = m_vel1Dir.perpInPlane(colInfo.floorNrm, true);
656 dynamics()->setMovingObjVel(dynamics()->movingObjVel().rej(colInfo.floorNrm));
657 dynamics()->setMovingRoadVel(dynamics()->movingRoadVel().rej(colInfo.floorNrm));
658
660 m_up = colInfo.floorNrm;
661 m_smoothedUp = colInfo.floorNrm;
662 }
663
664 stickyRoad = true;
665
666 break;
667 }
668 vel *= 0.5f;
669 pos += -STICKY_RADIUS * componentYAxis();
670 }
671
672 if (!stickyRoad) {
674 }
675}
676
682
684 m_kclSpeedFactor = 1.0f;
686 } else {
687 bool anyWheel = status.onBit(eStatus::AnyWheelCollision);
688 if (anyWheel) {
692 }
693
695 const CollisionData &colData = collisionData();
696 if (anyWheel) {
697 if (colData.speedFactor < m_kclWheelSpeedFactor) {
699 }
701 static_cast<f32>(m_floorCollisionCount + 1);
702 } else {
704 m_kclRotFactor = colData.rotFactor;
705 }
706 }
707 }
708
710}
711
714 auto *objDir = Field::ObjectDirector::Instance();
715 auto *psea = objDir->psea();
716 if (!psea) {
717 return;
718 }
719
720 f32 pos = wheelPos(0).y;
721 u16 count = tireCount();
722 for (u16 wheelIdx = 0; wheelIdx < count; ++wheelIdx) {
723 f32 tmp = wheelEdgePos(wheelIdx).y;
724 if (wheelIdx == 0 || tmp < pos) {
725 pos = tmp;
726 }
727 }
728
729 if (objDir->risingWaterKillPlaneHeight() > pos) {
730 collide()->activateOob(true, nullptr, false, false);
731 }
732
733 f32 dist = -objDir->distAboveRisingWater(pos);
734 if (dist > 0.0f && status().offBit(Kart::eStatus::BoostOffroadInvincibility)) {
735 f32 speedScale = std::min(1.0f, dist / 100.0f);
736 m_kclSpeedFactor = 1.0f - (1.0f - param()->stats().kclSpeed[3]) * speedScale;
737 }
738}
739
743
744 if (m_boost.calc()) {
746 } else {
748 }
749
751}
752
756
758 return;
759 }
760
762 if (--m_rampBoost < 1) {
763 m_rampBoost = 0;
765 }
766}
767
784
789 constexpr s16 MAX_SSMT_CHARGE = 75;
790 constexpr s16 SSMT_BOOST_FRAMES = 30;
791 constexpr s16 LEEWAY_FRAMES = 1;
792 constexpr s16 DISABLE_ACCEL_FRAMES = 20;
793
795
797
799 if (++m_ssmtCharge > MAX_SSMT_CHARGE) {
800 m_ssmtCharge = MAX_SSMT_CHARGE;
803 }
804
805 return;
806 }
807
808 m_ssmtCharge = 0;
809
811 return;
812 }
813
815 if (--m_ssmtLeewayTimer < 0) {
818 m_ssmtDisableAccelTimer = DISABLE_ACCEL_FRAMES;
820 } else {
822 activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
825 }
826 }
827 } else {
829 activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
832 } else {
833 m_ssmtLeewayTimer = LEEWAY_FRAMES;
836 m_ssmtDisableAccelTimer = LEEWAY_FRAMES;
837 }
838 }
839}
840
847
853 if (m_hopStickX == 0) {
855 m_hopStickX = -1;
856 } else if (status.onBit(eStatus::StickLeft)) {
857 m_hopStickX = 1;
858 }
860 onHop();
861 }
862 }
863 }
864 }
865
867 if (m_hopStickX == 0) {
869 m_hopStickX = -1;
870 } else if (status.onBit(eStatus::StickLeft)) {
871 m_hopStickX = 1;
872 }
873 }
874 if (m_hopFrame < 3) {
875 ++m_hopFrame;
876 }
878 m_hopFrame = 0;
879 }
880
882}
883
895
913
919
925
931
937
945
951
955
960 constexpr s16 AUTO_DRIFT_START_DELAY = 12;
961
963
965 return;
966 }
967
968 if (canStartDrift() &&
970 EGG::Mathf::abs(state()->stickX()) > 0.85f) {
972 std::min<s16>(AUTO_DRIFT_START_DELAY, m_autoDriftStartFrameCounter + 1);
973 } else {
975 }
976
977 if (m_autoDriftStartFrameCounter >= AUTO_DRIFT_START_DELAY) {
979
981 if (state()->stickX() < 0.0f) {
982 m_hopStickX = 1;
984
985 } else {
986 m_hopStickX = -1;
988 }
989 }
990
991 f32 halfTarget = 0.5f * param()->stats().driftOutsideTargetAngle;
992 m_autoDriftAngle = std::clamp(m_autoDriftAngle, -halfTarget, halfTarget);
993 } else {
995 m_hopStickX = 0;
996
997 if (m_autoDriftAngle > 0.0f) {
999 std::max(0.0f, m_autoDriftAngle - param()->stats().driftOutsideDecrement);
1000 } else {
1002 std::min(0.0f, m_autoDriftAngle + param()->stats().driftOutsideDecrement);
1003 }
1004 }
1005
1006 EGG::Quatf angleAxis;
1007 angleAxis.setAxisRotation(-m_autoDriftAngle * DEG2RAD, m_up);
1008 physics()->composeExtraRot(angleAxis);
1009}
1010
1015 bool isHopping = calcPreDrift();
1017
1020
1022 param()->stats().driftType != KartParam::Stats::DriftType::Inside_Drift_Bike &&
1028
1029 if (driftRej.normalise() != 0.0f) {
1030 f32 rejCrossDirMag = driftRej.cross(rotZ).length();
1031 f32 angle = EGG::Mathf::atan2(rejCrossDirMag, driftRej.dot(rotZ));
1032 f32 sign = 1.0f;
1033 if ((rotZ.z * (rotZ.x - driftRej.x)) - (rotZ.x * (rotZ.z - driftRej.z)) > 0.0f) {
1034 sign = -1.0f;
1035 }
1036
1037 m_outsideDriftAngle += angle * RAD2DEG * sign;
1038 }
1039 }
1040
1041 m_outsideDriftLastDir = rotZ;
1042 }
1043
1044 // TODO: Is this backwards/inverted?
1045 if (((status.offBit(eStatus::Hop) || m_hopFrame < 3) &&
1048 if (canHop()) {
1049 hop();
1050 isHopping = true;
1051 }
1052 } else {
1054 isHopping = false;
1055 }
1056
1058
1060 if (!isHopping && status.onBit(eStatus::TouchingGround)) {
1062
1063 if (action()->flags().offBit(KartAction::eFlags::Rotating) || m_speed <= 20.0f) {
1064 f32 driftAngleDecr = param()->stats().driftOutsideDecrement;
1065 if (m_outsideDriftAngle > 0.0f) {
1066 m_outsideDriftAngle = std::max(0.0f, m_outsideDriftAngle - driftAngleDecr);
1067 } else if (m_outsideDriftAngle < 0.0f) {
1068 m_outsideDriftAngle = std::min(0.0f, m_outsideDriftAngle + driftAngleDecr);
1069 }
1070 }
1071 }
1072 } else {
1073 // This is a different comparison than @ref KartMove::canStartDrift().
1075
1080 !canStartDrift)) {
1081 if (canStartDrift) {
1082 releaseMt();
1083 }
1084
1087 } else {
1089 }
1090 }
1091}
1092
1097 constexpr f32 OUTSIDE_DRIFT_BONUS = 0.5f;
1098
1099 const auto &stats = param()->stats();
1101
1102 if (stats.driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1103 f32 driftAngle = 0.0f;
1104
1105 if (status.onBit(eStatus::Hop)) {
1107 EGG::Vector3f rotRej = rotZ.rej(m_hopUp);
1108
1109 if (rotRej.normalise() != 0.0f) {
1110 const EGG::Vector3f hopCrossRot = m_hopDir.cross(rotRej);
1111 driftAngle =
1112 EGG::Mathf::atan2(hopCrossRot.length(), m_hopDir.dot(rotRej)) * RAD2DEG;
1113 }
1114 }
1115
1116 m_outsideDriftAngle += driftAngle * static_cast<f32>(-m_hopStickX);
1117 m_outsideDriftAngle = std::clamp(m_outsideDriftAngle, -60.0f, 60.0f);
1118 }
1119
1121
1123 return;
1124 }
1125
1126 if (getAppliedHopStickX() == 0) {
1127 return;
1128 }
1129
1132 m_outsideDriftBonus = OUTSIDE_DRIFT_BONUS * (m_speedRatioCapped * stats.driftManualTightness);
1133}
1134
1139 constexpr f32 SMT_LENGTH_FACTOR = 3.0f;
1140
1142
1145 return;
1146 }
1147
1148 u16 mtLength = param()->stats().miniTurbo;
1149
1151 mtLength *= SMT_LENGTH_FACTOR;
1152 }
1153
1156 }
1157
1159}
1160
1165 if (state()->airtime() > 5) {
1166 return;
1167 }
1168
1169 if (param()->stats().driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1170 if (m_hopStickX == -1) {
1171 f32 angle = m_outsideDriftAngle;
1172 f32 targetAngle = param()->stats().driftOutsideTargetAngle;
1173 if (angle > targetAngle) {
1174 m_outsideDriftAngle = std::max(m_outsideDriftAngle - 2.0f, targetAngle);
1175 } else if (angle < targetAngle) {
1177 m_outsideDriftAngle = std::min(m_outsideDriftAngle, targetAngle);
1178 }
1179 } else if (m_hopStickX == 1) {
1180 f32 angle = m_outsideDriftAngle;
1181 f32 targetAngle = -param()->stats().driftOutsideTargetAngle;
1182 if (targetAngle > angle) {
1183 m_outsideDriftAngle = std::min(m_outsideDriftAngle + 2.0f, targetAngle);
1184 } else if (targetAngle < angle) {
1186 m_outsideDriftAngle = std::max(m_outsideDriftAngle, targetAngle);
1187 }
1188 }
1189 }
1190
1191 calcMtCharge();
1192}
1193
1198 f32 turn;
1201 bool autoDrift = status.onBit(eStatus::AutoDrift);
1202 const auto &stats = param()->stats();
1203
1204 if (drifting) {
1205 turn = autoDrift ? stats.driftAutomaticTightness : stats.driftManualTightness;
1206 } else {
1207 turn = autoDrift ? stats.handlingAutomaticTightness : stats.handlingManualTightness;
1208 }
1209
1210 if (drifting && stats.driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1211 m_outsideDriftBonus *= 0.99f;
1212 turn += m_outsideDriftBonus;
1213 }
1214
1215 bool forwards = true;
1216 if (status.onBit(eStatus::Brake) && m_speed <= 0.0f) {
1217 forwards = false;
1218 }
1219
1220 turn *= m_realTurn;
1222 turn = m_realTurn * 0.04f;
1223 } else {
1224 if (status.onBit(eStatus::Hop) && m_hopPosY > 0.0f) {
1225 turn *= 1.4f;
1226 }
1227
1228 if (!drifting) {
1229 bool noTurn = false;
1231 EGG::Mathf::abs(m_speed) < 1.0f) {
1232 if (!(status.onBit(eStatus::Hop) && m_hopPosY > 0.0f)) {
1233 turn = 0.0f;
1234 noTurn = true;
1235 }
1236 }
1237 if (forwards && !noTurn) {
1238 if (m_speed >= 20.0f) {
1239 turn *= 0.5f;
1240 if (m_speed < 70.0f) {
1241 turn += (1.0f - (m_speed - 20.0f) / 50.0f) * turn;
1242 }
1243 } else {
1244 turn = (turn * 0.4f) + (m_speed / 20.0f) * (turn * 0.6f);
1245 }
1246 }
1247 }
1248
1249 if (!forwards) {
1250 turn = -turn;
1251 }
1252
1254 turn *= 2.0f;
1255 }
1256
1257 f32 stickX = EGG::Mathf::abs(state()->stickX());
1258 if (autoDrift && stickX > 0.3f) {
1259 f32 stickScalar = (stickX - 0.3f) / 0.7f;
1260 stickX = drifting ? 0.2f : 0.5f;
1261 turn += stickScalar * (turn * stickX * m_speedRatioCapped);
1262 }
1263 }
1264
1268 turn = 0.0f;
1270 u32 airtime = state()->airtime();
1271 if (airtime >= 70) {
1272 turn = 0.0f;
1273 } else if (airtime >= 30) {
1274 turn = std::max(0.0f, turn * (1.0f - (airtime - 30) * 0.025f));
1275 }
1276 }
1277 }
1278
1280 f32 angle = EGG::Mathf::atan2(forward.cross(m_dir).length(), forward.dot(m_dir));
1281 angle = EGG::Mathf::abs(angle) * RAD2DEG;
1282
1283 if (angle > 60.0f) {
1284 turn *= std::max(0.0f, 1.0f - (angle - 60.0f) / 40.0f);
1285 }
1286 }
1287
1288 calcVehicleRotation(turn);
1289}
1290
1295 const auto *raceMgr = System::RaceManager::Instance();
1297
1298 if (raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
1299 f32 speedFix = dynamics()->speedFix();
1301 ((status.onBit(eStatus::WallCollisionStart) || state()->wallBonkTimer() == 0 ||
1302 EGG::Mathf::abs(speedFix) >= 3.0f) &&
1304 m_speed += speedFix;
1305 }
1306 }
1307
1308 if (m_speed < -20.0f) {
1309 m_speed += 0.5f;
1310 }
1311
1312 bool water = false;
1313
1316 status.offBit(eStatus::MushroomBoost) && EGG::Mathf::abs(m_speed) > 5.0f)) {
1317 water = true;
1319 }
1320
1321 m_acceleration = 0.0f;
1322 m_speedDragMultiplier = 1.0f;
1323
1326 return;
1327 }
1328
1333 if (status.onBit(eStatus::RampBoost) && state()->airtime() < 4) {
1334 m_acceleration = 7.0f;
1335 } else {
1337 m_speedDragMultiplier = 0.99f;
1338 } else {
1340 m_speedDragMultiplier = 0.999f;
1341 } else {
1342 if (state()->airtime() > 5) {
1343 m_speedDragMultiplier = 0.999f;
1344 }
1345 }
1346 }
1348 }
1349 } else if (status.offBit(eStatus::Boost)) {
1354 } else {
1357 m_speed *= m_speed > 0.0f ? 0.98f : 0.95f;
1359 m_acceleration = -1.5f;
1361 if (++m_backwardsAllowCounter > 15) {
1363 }
1365 m_acceleration = -2.0f;
1366 }
1367 }
1368
1370 const auto &stats = param()->stats();
1371
1372 f32 x = 1.0f - EGG::Mathf::abs(m_weightedTurn) * m_speedRatioCapped;
1373 m_speed *= stats.turningSpeed + (1.0f - stats.turningSpeed) * x;
1374 }
1375 } else {
1376 m_acceleration = water ? calcVehicleAcceleration() : 7.0f;
1377 }
1378 } else {
1380 }
1381}
1382
1386 f32 vel = 0.0f;
1387 f32 initialVel = 1.0f - m_smoothedUp.y;
1388 if (EGG::Mathf::abs(m_speed) < 30.0f && m_smoothedUp.y > 0.0f && initialVel > 0.0f) {
1389 initialVel = std::min(initialVel * 2.0f, 2.0f);
1390 vel += initialVel;
1391 vel *= std::clamp(-bodyFront().y, -0.5f, 0.5f);
1392 }
1393 m_speed += vel;
1394}
1395
1400 f32 ratio = m_speed / m_softSpeedLimit;
1401 if (ratio < 0.0f) {
1402 return 1.0f;
1403 }
1404
1405 std::span<const f32> as;
1406 std::span<const f32> ts;
1407 if (state()->isDrifting()) {
1408 as = param()->stats().accelerationDriftA;
1409 ts = param()->stats().accelerationDriftT;
1410 } else {
1413 }
1414
1415 size_t i = 0;
1416 f32 acceleration = 0.0f;
1417 f32 t_curr = 0.0f;
1418 for (; i < ts.size(); ++i) {
1419 if (ratio < ts[i]) {
1420 acceleration = as[i] + ((as[i + 1] - as[i]) / (ts[i] - t_curr)) * (ratio - t_curr);
1421 break;
1422 }
1423
1424 t_curr = ts[i];
1425 }
1426
1427 return i < ts.size() ? acceleration : as.back();
1428}
1429
1434 constexpr f32 ROTATION_SCALAR_NORMAL = 0.5f;
1435 constexpr f32 ROTATION_SCALAR_MIDAIR = 0.2f;
1436 constexpr f32 ROTATION_SCALAR_BOOST_RAMP = 4.0f;
1437 constexpr f32 OOB_SLOWDOWN_RATE = 0.95f;
1438 constexpr f32 TERMINAL_VELOCITY = 90.0f;
1439
1442
1445 }
1446
1448 m_speed = 0.0f;
1449 } else {
1450 if (m_acceleration < 0.0f) {
1451 if (m_speed < -20.0f) {
1452 m_acceleration = 0.0f;
1453 } else {
1454 if (m_speed + m_acceleration <= -20.0f) {
1455 m_acceleration = -20.0f - m_speed;
1456 }
1457 }
1458 }
1459
1461 }
1462
1464 m_speed *= OOB_SLOWDOWN_RATE;
1465 } else {
1467 m_speed *= 0.8f;
1468 } else {
1470 m_speed = 0.0f;
1473 }
1474 }
1475 }
1476
1478 const f32 boostMultiplier = m_boost.multiplier();
1479 const f32 boostSpdLimit = m_boost.speedLimit();
1480 m_jumpPadBoostMultiplier = boostMultiplier;
1481
1482 f32 scaleMultiplier = m_shockSpeedMultiplier;
1484 scaleMultiplier *= 0.7f;
1485 }
1486
1487 f32 wheelieBonus = boostMultiplier + getWheelieSoftSpeedLimitBonus();
1488 speedLimit *= status.onBit(eStatus::JumpPadFixedSpeed) ?
1489 1.0f :
1490 scaleMultiplier * (wheelieBonus * m_kclSpeedFactor);
1491
1494 f32 boostSpeed = ignoreScale ? 1.0f : scaleMultiplier;
1495 boostSpeed *= boostSpdLimit * m_kclSpeedFactor;
1496
1497 if (status.offBit(eStatus::JumpPad) && boostSpeed > 0.0f && boostSpeed > speedLimit) {
1498 speedLimit = boostSpeed;
1499 }
1500
1501 m_jumpPadSoftSpeedLimit = boostSpdLimit * m_kclSpeedFactor;
1502
1504 speedLimit = std::max(speedLimit, 100.0f);
1505 }
1506
1507 m_lastDir = (m_speed > 0.0f) ? 1.0f * m_dir : -1.0f * m_dir;
1508
1509 f32 local_c8 = 1.0f;
1510 speedLimit *= calcWallCollisionSpeedFactor(local_c8);
1511
1512 if (m_softSpeedLimit <= speedLimit) {
1513 m_softSpeedLimit = speedLimit;
1515 m_softSpeedLimit = std::max(m_softSpeedLimit - 3.0f, speedLimit);
1516 } else {
1517 m_softSpeedLimit = speedLimit;
1518 }
1519
1521
1523
1525 m_speed = std::max(m_speed, m_jumpPadMinSpeed);
1526 }
1527
1528 calcWallCollisionStart(local_c8);
1529
1530 m_speedRatio = EGG::Mathf::abs(m_speed / m_baseSpeed);
1531 m_speedRatioCapped = std::min(1.0f, m_speedRatio);
1532
1534 if (m_speed < 0.0f) {
1535 crossVec = -crossVec;
1536 }
1537
1538 f32 rotationScalar = ROTATION_SCALAR_NORMAL;
1539 if (collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::BoostRamp)) {
1540 rotationScalar = ROTATION_SCALAR_BOOST_RAMP;
1542 rotationScalar = ROTATION_SCALAR_MIDAIR;
1543 }
1544
1545 EGG::Matrix34f local_90;
1546 local_90.setAxisRotation(DEG2RAD * rotationScalar, crossVec);
1547 m_vel1Dir = local_90.multVector33(m_vel1Dir);
1548
1549 const auto *raceMgr = System::RaceManager::Instance();
1552 raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
1554 }
1555
1557 EGG::Vector3f nextSpeed = m_speed * m_vel1Dir;
1558
1560 TERMINAL_VELOCITY;
1561 nextSpeed.y = std::min(nextSpeed.y, maxSpeedY);
1562
1563 dynamics()->setIntVel(dynamics()->intVel() + nextSpeed);
1564
1571 }
1572 } else {
1573 if (m_processedSpeed >= 0.0f) {
1575 }
1576 }
1577 } else {
1579 }
1580}
1581
1587
1589 return 1.0f;
1590 }
1591
1593
1595 return 1.0f;
1596 }
1597
1599 if (wallNrm.y > 0.0f) {
1600 wallNrm.y = 0.0f;
1601 wallNrm.normalise();
1602 }
1603
1604 f32 dot = m_lastDir.dot(wallNrm);
1605
1606 if (dot < 0.0f) {
1607 f1 = std::max(0.0f, dot + 1.0f);
1608
1609 return std::min(1.0f, f1 * (status.onBit(eStatus::WallCollision) ? 0.4f : 0.7f));
1610 }
1611
1612 return 1.0f;
1613}
1614
1620
1622
1624 return;
1625 }
1626
1627 m_outsideDriftAngle = 0.0f;
1629 m_dir = bodyFront();
1630 m_vel1Dir = m_dir;
1633 }
1634
1636 f32 speedDiff = m_lastSpeed - m_speed;
1637 const CollisionData &colData = collisionData();
1638
1639 if (speedDiff > 30.0f) {
1641 EGG::Vector3f newPos = colData.relPos + pos();
1642 f32 dot = -bodyUp().dot(colData.relPos) * 0.5f;
1643 EGG::Vector3f scaledUp = dot * bodyUp();
1644 newPos -= scaledUp;
1645
1646 speedDiff = std::min(60.0f, speedDiff);
1647 EGG::Vector3f scaledWallNrm = speedDiff * colData.wallNrm;
1648
1649 auto [proj, rej] = scaledWallNrm.projAndRej(m_vel1Dir);
1650 proj *= 0.3f;
1651 rej *= 0.9f;
1652
1654 proj = EGG::Vector3f::zero;
1655 rej = EGG::Vector3f::zero;
1656 }
1657
1658 if (bodyFront().dot(colData.wallNrm) > 0.0f) {
1659 proj = EGG::Vector3f::zero;
1660 }
1661 rej *= 0.9f;
1662
1663 EGG::Vector3f projRejSum = proj + rej;
1664 f32 bumpDeviation = 0.0f;
1666 bumpDeviation = param()->stats().bumpDeviationLevel;
1667 }
1668
1669 dynamics()->applyWrenchScaled(newPos, projRejSum, bumpDeviation);
1670 } else if (wallKclType() == COL_TYPE_SPECIAL_WALL && wallKclVariant() == 2) {
1671 dynamics()->addForce(colData.wallNrm * 15.0f);
1673 }
1674
1676 dynamics()->addForce(colData.wallNrm * 15.0f);
1678 }
1679 }
1680}
1681
1686 f32 next = 0.0f;
1687 f32 scalar = 1.0f;
1688
1690
1693 next = 0.015f * -state()->startBoostCharge();
1694 } else if (status.offBit(eStatus::ChargingSSMT)) {
1697 f32 speedDiff = m_lastSpeed - m_speed;
1698 scalar = std::clamp(speedDiff, -3.0f, 3.0f);
1699
1701 next = (scalar * 0.15f) * 0.25f;
1703 next *= 0.5f;
1704 }
1705 } else {
1706 next = (scalar * 0.15f) * 0.08f;
1707 }
1709 }
1710 } else {
1711 constexpr s16 MAX_SSMT_CHARGE = 75;
1712 next = 0.015f * (-static_cast<f32>(m_ssmtCharge) / static_cast<f32>(MAX_SSMT_CHARGE));
1713 }
1714 }
1715
1717 m_standStillBoostRot = isBike() ? next * 3.0f : next * 10.0f;
1718 } else {
1720 }
1721}
1722
1727 constexpr f32 DIVE_LIMIT = 0.8f;
1728
1729 m_divingRot *= 0.96f;
1730
1732
1735 return;
1736 }
1737
1738 f32 stickY = state()->stickY();
1739
1741 stickY = std::min(1.0f, stickY + 0.4f);
1742 }
1743
1744 u32 airtime = state()->airtime();
1745
1746 if (airtime > 50) {
1747 if (EGG::Mathf::abs(stickY) < 0.1f) {
1748 m_divingRot += 0.05f * (-0.025f - m_divingRot);
1749 }
1750 } else {
1751 stickY *= (airtime / 50.0f);
1752 }
1753
1754 m_divingRot = std::clamp(m_divingRot + stickY * 0.005f, -DIVE_LIMIT, DIVE_LIMIT);
1755
1759
1760 if (state()->airtime() < 50) {
1761 return;
1762 }
1763
1766 f32 upDotTop = m_up.dot(topRotated);
1767 EGG::Vector3f upCrossTop = m_up.cross(topRotated);
1768 f32 crossNorm = upCrossTop.length();
1769 f32 angle = EGG::Mathf::abs(EGG::Mathf::atan2(crossNorm, upDotTop));
1770
1771 f32 fVar1 = angle * RAD2DEG - 20.0f;
1772 if (fVar1 <= 0.0f) {
1773 return;
1774 }
1775
1776 f32 mult = std::min(1.0f, fVar1 / 20.0f);
1777 if (forwardRotated.y > 0.0f) {
1778 dynamics()->setGravity((1.0f - 0.2f * mult) * dynamics()->gravity());
1779 } else {
1780 dynamics()->setGravity((0.2f * mult + 1.0f) * dynamics()->gravity());
1781 }
1782}
1783
1798
1801 m_hopVelY = m_hopVelY * 0.998f + m_hopGravity;
1803
1804 if (m_hopPosY < 0.0f) {
1805 m_hopPosY = 0.0f;
1806 m_hopVelY = 0.0f;
1807 }
1808}
1809
1814
1817 EGG::Vector3f &upLocal, const EGG::Vector3f &prevPos, Field::CollisionInfo *colInfo,
1818 Field::KCLTypeMask *maskOut, Field::KCLTypeMask flags) const {
1820 pos = dynamics()->pos() + (-scale * m_scale.y) * upLocal;
1821
1822 auto *colDir = Field::CollisionDirector::Instance();
1823 return colDir->checkSphereFullPush(radius, pos, prevPos, flags, colInfo, maskOut, 0);
1824}
1825
1828 f32 dotNorm = std::clamp(from.dot(to), -1.0f, 1.0f);
1829 f32 acos = EGG::Mathf::acos(dotNorm);
1830 return acos > 0.0f ? std::min(0.1f, scale / acos) : 0.1f;
1831}
1832
1834void KartMove::applyForce(f32 force, const EGG::Vector3f &hitDir, bool stop) {
1835 constexpr s16 BUMP_COOLDOWN = 5;
1836
1837 if (m_bumpTimer >= 1) {
1838 return;
1839 }
1840
1841 dynamics()->addForce(force * hitDir.perpInPlane(m_up, true));
1843
1844 m_bumpTimer = BUMP_COOLDOWN;
1845
1846 if (stop) {
1847 m_speed = 0.0f;
1848 }
1849}
1850
1854 f32 tiltMagnitude = 0.0f;
1856
1859 EGG::Vector3f front = componentZAxis();
1860 front = front.perpInPlane(m_up, true);
1861 EGG::Vector3f frontSpeed = velocity().rej(front).perpInPlane(m_up, false);
1862
1863 if (frontSpeed.squaredLength() > std::numeric_limits<f32>::epsilon()) {
1864 tiltMagnitude = frontSpeed.length();
1865
1866 if (front.z * frontSpeed.x - front.x * frontSpeed.z > 0.0f) {
1867 tiltMagnitude = -tiltMagnitude;
1868 }
1869
1870 tiltMagnitude = std::clamp(tiltMagnitude, -1.0f, 1.0f);
1871 }
1872 } else if (status.offBit(eStatus::Hop) || m_hopPosY <= 0.0f) {
1873 EGG::Vector3f angVel0 = dynamics()->angVel0();
1874 angVel0.z *= 0.98f;
1875 dynamics()->setAngVel0(angVel0);
1876 }
1877
1878 f32 lean =
1879 m_invScale * (tiltMagnitude * param()->stats().tilt * EGG::Mathf::abs(m_weightedTurn));
1880
1882
1883 EGG::Vector3f angVel0 = dynamics()->angVel0();
1884 angVel0.x += m_standStillBoostRot;
1885 angVel0.z += lean;
1886 dynamics()->setAngVel0(angVel0);
1887
1889 angVel2.y += turn;
1891
1892 calcDive();
1893}
1894
1899 // TODO: Some of these are shared between the base and derived class implementations.
1900 constexpr u16 MAX_MT_CHARGE = 270;
1901 constexpr u16 MAX_SMT_CHARGE = 300;
1902 constexpr u16 BASE_MT_CHARGE = 2;
1903 constexpr u16 BASE_SMT_CHARGE = 2;
1904 constexpr f32 BONUS_CHARGE_STICK_THRESHOLD = 0.4f;
1905 constexpr u16 EXTRA_MT_CHARGE = 3;
1906
1908 return;
1909 }
1910
1911 f32 stickX = state()->stickX();
1912
1914 m_mtCharge += BASE_MT_CHARGE;
1915
1916 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
1917 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
1918 m_mtCharge += EXTRA_MT_CHARGE;
1919 }
1920 } else if (m_hopStickX != -1) {
1921 m_mtCharge += EXTRA_MT_CHARGE;
1922 }
1923
1924 if (m_mtCharge > MAX_MT_CHARGE) {
1925 m_mtCharge = MAX_MT_CHARGE;
1927 }
1928 }
1929
1931 return;
1932 }
1933
1934 m_smtCharge += BASE_SMT_CHARGE;
1935
1936 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
1937 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
1938 m_smtCharge += EXTRA_MT_CHARGE;
1939 }
1940 } else if (m_hopStickX != -1) {
1941 m_smtCharge += EXTRA_MT_CHARGE;
1942 }
1943
1944 if (m_smtCharge > MAX_SMT_CHARGE) {
1945 m_smtCharge = MAX_SMT_CHARGE;
1947 }
1948}
1949
1959
1965 onHop();
1966
1970 m_smtCharge = 0;
1971 m_mtCharge = 0;
1972 m_hopStickX = 0;
1973 m_hopFrame = 0;
1974 m_hopPosY = 0.0f;
1977 m_outsideDriftBonus = 0.0f;
1978
1980 extVel.y = 0.0f + m_hopVelY;
1982
1983 EGG::Vector3f totalForce = dynamics()->totalForce();
1984 totalForce.y = 0.0f;
1985 dynamics()->setTotalForce(totalForce);
1986}
1987
1990 constexpr s16 BOOST_PANEL_DURATION = 60;
1991
1993 return;
1994 }
1995
1997 setOffroadInvincibility(BOOST_PANEL_DURATION);
1998}
1999
2004 constexpr s16 BOOST_RAMP_DURATION = 60;
2005
2007
2009 return;
2010 }
2011
2013 m_rampBoost = BOOST_RAMP_DURATION;
2014 setOffroadInvincibility(BOOST_RAMP_DURATION);
2015}
2016
2022 static constexpr std::array<JumpPadProperties, 8> JUMP_PAD_PROPERTIES = {{
2023 {50.0f, 50.0f, 35.0f},
2024 {50.0f, 50.0f, 47.0f},
2025 {59.0f, 59.0f, 30.0f},
2026 {73.0f, 73.0f, 45.0f},
2027 {73.0f, 73.0f, 53.0f},
2028 {56.0f, 56.0f, 50.0f},
2029 {55.0f, 55.0f, 35.0f},
2030 {56.0f, 56.0f, 50.0f},
2031 }};
2032
2034
2036 return;
2037 }
2038
2040 s32 jumpPadVariant = state()->jumpPadVariant();
2041 m_jumpPadProperties = &JUMP_PAD_PROPERTIES[jumpPadVariant];
2042
2043 if (jumpPadVariant == 3 || jumpPadVariant == 4) {
2044 if (m_jumpPadBoostMultiplier > 1.3f || m_jumpPadSoftSpeedLimit > 110.0f) {
2045 // Set speed to 100 if the player has boost from a boost panel or mushroom(item) before
2046 // hitting the jump pad
2047 static constexpr std::array<JumpPadProperties, 2> JUMP_PAD_PROPERTIES_SHROOM_BOOST = {{
2048 {100.0f, 100.0f, 70.0f},
2049 {100.0f, 100.0f, 65.0f},
2050 }};
2051 m_jumpPadProperties = &JUMP_PAD_PROPERTIES_SHROOM_BOOST[jumpPadVariant != 3];
2052 }
2053
2055 }
2056
2057 if (jumpPadVariant == 4) {
2060 } else {
2062 EGG::Vector3f totalForce = dynamics()->totalForce();
2063
2065 totalForce.y = 0.0f;
2066
2068 dynamics()->setTotalForce(totalForce);
2069
2070 if (jumpPadVariant != 3) {
2072 dir.y = 0.0f;
2073 dir.normalise();
2074 m_speed *= m_dir.dot(dir);
2075 m_dir = dir;
2076 m_vel1Dir = dir;
2078 }
2079 }
2080
2083 m_speed = std::max(m_speed, m_jumpPadMinSpeed);
2084}
2085
2110
2116
2119 if (m_boost.activate(type, frames)) {
2121 }
2122}
2123
2128
2131 constexpr s16 MUSHROOM_DURATION = 90;
2132
2134
2136 return;
2137 }
2138
2140
2141 m_mushroomBoostTimer = MUSHROOM_DURATION;
2143 setOffroadInvincibility(MUSHROOM_DURATION);
2144}
2145
2148 constexpr s16 BASE_DURATION = 50;
2149 constexpr s16 TRICK_DURATION = 100;
2150
2152
2154 return;
2155 }
2156
2157 s16 boostDuration = status.onBit(eStatus::ZipperTrick) ? TRICK_DURATION : BASE_DURATION;
2159
2160 setOffroadInvincibility(boostDuration);
2162 m_zipperBoostMax = boostDuration;
2164}
2165
2177
2183
2185 return;
2186 }
2187
2188 if (--m_offroadInvincibility > 0) {
2189 return;
2190 }
2191
2193}
2194
2199
2201 return;
2202 }
2203
2204 if (--m_mushroomBoostTimer > 0) {
2205 return;
2206 }
2207
2209}
2210
2214
2216 return;
2217 }
2218
2220
2224 }
2225
2226 if (m_zipperBoostTimer < 10) {
2227 EGG::Vector3f angVel = dynamics()->angVel0();
2228 angVel.y = 0.0f;
2229 dynamics()->setAngVel0(angVel);
2230 }
2231}
2232
2235 static constexpr std::array<s16, 3> KART_TRICK_BOOST_DURATION = {{
2236 40,
2237 70,
2238 85,
2239 }};
2240 static constexpr std::array<s16, 3> BIKE_TRICK_BOOST_DURATION = {{
2241 45,
2242 80,
2243 95,
2244 }};
2245
2247 return;
2248 }
2249
2250 s16 duration;
2251 if (isBike()) {
2252 duration = BIKE_TRICK_BOOST_DURATION[static_cast<u32>(m_jump->variant())];
2253 } else {
2254 duration = KART_TRICK_BOOST_DURATION[static_cast<u32>(m_jump->variant())];
2255 }
2256
2258}
2259
2266
2269 if (status().offBit(eStatus::Crushed)) {
2270 return;
2271 }
2272
2273 if (--m_crushTimer == 0) {
2276 }
2277}
2278
2281 m_kartScale->calc();
2282
2283 const EGG::Vector3f sizeScale = m_kartScale->sizeScale();
2284 setScale(m_kartScale->pressScale() * sizeScale);
2286 m_hitboxScale = std::max(sizeScale.z, m_totalScale);
2287
2288 if (sizeScale.z != 1.0f) {
2290 }
2291
2292 m_invScale = m_scale.z > 1.0f ? 1.0f / m_scale.z : 1.0f;
2293}
2294
2297 auto &status = state()->status();
2298
2300 return;
2301 }
2302
2306
2307 if (timer > m_shockTimer) {
2308 m_shockTimer = timer;
2310 }
2311}
2312
2315 auto &status = state()->status();
2316
2318 if (--m_shockTimer == 0) {
2319 deactivateShock(false);
2320 }
2321
2322 m_shockSpeedMultiplier = std::max(0.7f, m_shockSpeedMultiplier - 0.03f);
2323 } else {
2324 m_shockSpeedMultiplier = std::min(1.0f, m_shockSpeedMultiplier + 0.05f);
2325 }
2326}
2327
2329void KartMove::deactivateShock(bool resetSpeed) {
2331 m_shockTimer = 0;
2333
2334 if (resetSpeed) {
2336 }
2337}
2338
2372
2375 auto [cannonPos, cannonDir] = getCannonPosRot();
2376 EGG::Vector3f forwardXZ = cannonPos - m_cannonEntryPos - m_cannonProgress;
2377 EGG::Vector3f forward = forwardXZ;
2378 f32 forwardLength = forward.normalise();
2379 forwardXZ.y = 0;
2380 forwardXZ.normalise();
2382 local94.y = 0;
2383 local94.normalise();
2384 m_speedRatioCapped = 1.0f;
2385 m_speedRatio = 1.5f;
2386 EGG::Matrix34f cannonOrientation;
2387 cannonOrientation.makeOrthonormalBasis(forward, EGG::Vector3f::ey);
2388 EGG::Vector3f up = cannonOrientation.multVector33(EGG::Vector3f::ey);
2389 m_smoothedUp = up;
2390 m_up = up;
2391
2392 if (forwardLength < 30.0f || local94.dot(forwardXZ) <= 0.0f) {
2393 exitCannon();
2394 return;
2395 }
2396
2399 const auto *cannonPoint =
2400 System::CourseMap::Instance()->getCannonPoint(state()->cannonPointId());
2401 size_t cannonParameterIdx = std::max<s16>(0, cannonPoint->parameterIdx());
2402 ASSERT(cannonParameterIdx < CANNON_PARAMETERS.size());
2403 const auto &cannonParams = CANNON_PARAMETERS[cannonParameterIdx];
2404 f32 newSpeed = cannonParams.speed;
2405 if (forwardLength < cannonParams.decelFactor) {
2406 f32 factor = std::max(0.0f, forwardLength / cannonParams.decelFactor);
2407
2408 newSpeed = cannonParams.endDecel;
2409 if (newSpeed <= 0.0f) {
2410 newSpeed = m_baseSpeed;
2411 }
2412
2413 newSpeed += factor * (cannonParams.speed - newSpeed);
2414 if (cannonParams.endDecel > 0.0f) {
2415 m_speed = std::min(newSpeed, m_speed);
2416 }
2417 }
2418
2419 m_cannonProgress += m_cannonEntryOfs * newSpeed;
2420
2422 if (cannonParams.height > 0.0f) {
2423 f32 fVar9 = EGG::Mathf::SinFIdx(
2424 (1.0f - (forwardLength / m_cannonEntryOfsLength)) * 180.0f * DEG2FIDX);
2425 newPos = fVar9 * cannonParams.height * m_cannonOrthog;
2426 }
2427
2431
2432 calcRotCannon(forward);
2433
2435}
2436
2439 EGG::Vector3f local48 = forward;
2440 local48.normalise();
2441 EGG::Vector3f local54 = bodyFront();
2442 EGG::Vector3f local60 = local54 + ((local48 - local54) * 0.3f);
2443 local54.normalise();
2444 local60.normalise();
2445 // also local70, localA8
2446 EGG::Quatf local80;
2447 local80.makeVectorRotation(local54, local60);
2448 local80 *= dynamics()->fullRot();
2449 local80.normalise();
2450 EGG::Quatf localB8;
2452 EGG::Quatf newRot = local80.slerpTo(localB8.multSwap(local80), 0.3f);
2453 dynamics()->setFullRot(newRot);
2454 dynamics()->setMainRot(newRot);
2455}
2456
2468
2474
2477
2479KartMoveBike::~KartMoveBike() = default;
2480
2484 constexpr f32 MAX_WHEELIE_ROTATION = 0.07f;
2485 constexpr u16 WHEELIE_COOLDOWN = 20;
2486
2488 m_wheelieFrames = 0;
2489 m_maxWheelieRot = MAX_WHEELIE_ROTATION;
2490 m_wheelieCooldown = WHEELIE_COOLDOWN;
2491 m_wheelieRotDec = 0.0f;
2493}
2494
2503
2510
2515 f32 leanRotInc = m_turningParams->leanRotIncRace;
2516 f32 leanRotCap = m_turningParams->leanRotCapRace;
2517 const auto *raceManager = System::RaceManager::Instance();
2518
2520
2522 if (!raceManager->isStageReached(System::RaceManager::Stage::Race) ||
2523 EGG::Mathf::abs(m_speed) < 5.0f) {
2526 }
2527 } else {
2528 leanRotInc = m_turningParams->leanRotIncSSMT;
2529 leanRotCap = m_turningParams->leanRotCapSSMT;
2530 }
2531
2532 m_leanRotCap += 0.3f * (leanRotCap - m_leanRotCap);
2533 m_leanRotInc += 0.3f * (leanRotInc - m_leanRotInc);
2534
2535 f32 stickX = state()->stickX();
2536 f32 extVelXFactor = 0.0f;
2537 f32 leanRotMin = -m_leanRotCap;
2538 f32 leanRotMax = m_leanRotCap;
2539
2545 } else if (!state()->isDrifting()) {
2546 if (stickX <= 0.2f) {
2547 if (stickX >= -0.2f) {
2549 } else {
2551 extVelXFactor = m_turningParams->leanRotShallowFactor;
2552 }
2553 } else {
2555 extVelXFactor = -m_turningParams->leanRotShallowFactor;
2556 }
2557 } else {
2558 leanRotMax = m_turningParams->leanRotMaxDrift;
2559 leanRotMin = m_turningParams->leanRotMinDrift;
2560
2561 if (m_hopStickX == 1) {
2562 leanRotMin = -leanRotMax;
2563 leanRotMax = -m_turningParams->leanRotMinDrift;
2564 }
2565 if (m_hopStickX == -1) {
2566 if (stickX == 0.0f) {
2567 m_leanRot += (0.5f - m_leanRot) * 0.05f;
2568 } else {
2570 extVelXFactor = -m_turningParams->leanRotShallowFactor * stickX;
2571 }
2572 } else if (stickX == 0.0f) {
2573 m_leanRot += (-0.5f - m_leanRot) * 0.05f;
2574 } else {
2576 extVelXFactor = -m_turningParams->leanRotShallowFactor * stickX;
2577 }
2578 }
2579
2580 bool capped = false;
2581 if (leanRotMin <= m_leanRot) {
2582 if (leanRotMax < m_leanRot) {
2583 m_leanRot = leanRotMax;
2584 capped = true;
2585 }
2586 } else {
2587 m_leanRot = leanRotMin;
2588 capped = true;
2589 }
2590
2591 if (!capped) {
2592 dynamics()->setExtVel(dynamics()->extVel() + componentXAxis() * extVelXFactor);
2593 }
2594
2595 f32 leanRotScalar = state()->isDrifting() ? 0.065f : 0.05f;
2596
2598
2601 m_leanRot * leanRotScalar));
2602
2603 calcDive();
2604
2605 EGG::Vector3f top = m_up;
2606
2608 f32 scalar = (m_speed >= 0.0f) ? m_speedRatioCapped * 2.0f : 0.0f;
2609 scalar = std::min(1.0f, scalar);
2610 top = scalar * m_up + (1.0f - scalar) * EGG::Vector3f::ey;
2611
2612 if (std::numeric_limits<f32>::epsilon() < top.squaredLength()) {
2613 top.normalise();
2614 }
2615 }
2616
2617 dynamics()->setTop_(top);
2618}
2619
2625 static constexpr std::array<TurningParameters, 2> TURNING_PARAMS_ARRAY = {{
2626 {0.8f, 0.08f, 1.0f, 0.1f, 1.2f, 0.8f, 0.08f, 0.6f, 0.15f, 1.6f, 0.9f, 180},
2627 {1.0f, 0.1f, 1.0f, 0.05f, 1.5f, 0.7f, 0.08f, 0.6f, 0.15f, 1.3f, 0.9f, 180},
2628 }};
2629
2631
2632 if (param()->stats().driftType == KartParam::Stats::DriftType::Outside_Drift_Bike) {
2633 m_turningParams = &TURNING_PARAMS_ARRAY[0];
2634 } else if (param()->stats().driftType == KartParam::Stats::DriftType::Inside_Drift_Bike) {
2635 m_turningParams = &TURNING_PARAMS_ARRAY[1];
2636 }
2637
2641 } else {
2644 }
2645}
2646
2648void KartMoveBike::init(bool b1, bool b2) {
2649 KartMove::init(b1, b2);
2650
2651 m_leanRot = 0.0f;
2652 m_leanRotCap = 0.0f;
2653 m_leanRotInc = 0.0f;
2654 m_wheelieRot = 0.0f;
2655 m_maxWheelieRot = 0.0f;
2656 m_wheelieFrames = 0;
2659}
2660
2666
2670 constexpr u32 FAILED_WHEELIE_FRAMES = 15;
2671 constexpr f32 AUTO_WHEELIE_CANCEL_STICK_THRESHOLD = 0.85f;
2672
2674 m_wheelieCooldown = std::max(0, m_wheelieCooldown - 1);
2675
2677
2679 bool cancelAutoWheelie = false;
2680
2682 EGG::Mathf::abs(state()->stickX()) <= AUTO_WHEELIE_CANCEL_STICK_THRESHOLD) {
2684 } else {
2685 if (++m_autoHardStickXFrames > 15) {
2686 cancelAutoWheelie = true;
2687 }
2688 }
2689
2691 if (m_turningParams->maxWheelieFrames < m_wheelieFrames || cancelAutoWheelie ||
2692 (!canWheelie() && FAILED_WHEELIE_FRAMES <= m_wheelieFrames)) {
2693 cancelWheelie();
2694 } else {
2695 m_wheelieRot += 0.01f;
2696 EGG::Vector3f angVel0 = dynamics()->angVel0();
2697 angVel0.x *= 0.9f;
2698 dynamics()->setAngVel0(angVel0);
2699 }
2700 } else if (0.0f < m_wheelieRot) {
2701 m_wheelieRotDec -= 0.001f;
2702 m_wheelieRotDec = std::max(-0.03f, m_wheelieRotDec);
2704 }
2705
2706 m_wheelieRot = std::clamp(m_wheelieRot, 0.0f, m_maxWheelieRot);
2707
2708 f32 vel1DirUp = m_vel1Dir.dot(EGG::Vector3f::ey);
2709
2710 if (m_wheelieRot > 0.0f) {
2711 if (vel1DirUp <= 0.5f || m_wheelieFrames < FAILED_WHEELIE_FRAMES) {
2713 angVel2.x -= m_wheelieRot * (1.0f - EGG::Mathf::abs(vel1DirUp));
2715 } else {
2716 cancelWheelie();
2717 }
2718
2720 } else {
2722 }
2723}
2724
2731 if (status().onBit(eStatus::AutoDrift)) {
2732 return;
2733 }
2734
2735 cancelWheelie();
2736}
2737
2743
2748 constexpr u16 MAX_MT_CHARGE = 270;
2749 constexpr u16 BASE_MT_CHARGE = 2;
2750 constexpr f32 BONUS_CHARGE_STICK_THRESHOLD = 0.4f;
2751 constexpr u16 EXTRA_MT_CHARGE = 3;
2752
2754 return;
2755 }
2756
2757 m_mtCharge += BASE_MT_CHARGE;
2758
2759 f32 stickX = state()->stickX();
2760 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
2761 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
2762 m_mtCharge += EXTRA_MT_CHARGE;
2763 }
2764 } else if (m_hopStickX != -1) {
2765 m_mtCharge += EXTRA_MT_CHARGE;
2766 }
2767
2768 if (m_mtCharge > MAX_MT_CHARGE) {
2769 m_mtCharge = MAX_MT_CHARGE;
2771 }
2772}
2773
2779
2783 constexpr s16 COOLDOWN_FRAMES = 20;
2784 bool dpadUp = inputs()->currentState().trickUp();
2786
2788 if (dpadUp && status.onBit(eStatus::TouchingGround)) {
2791 return;
2792 }
2793
2794 if (m_wheelieCooldown > 0) {
2795 return;
2796 }
2797
2798 startWheelie();
2799 }
2800 } else if (inputs()->currentState().trickDown() && m_wheelieCooldown <= 0) {
2801 cancelWheelie();
2802 m_wheelieCooldown = COOLDOWN_FRAMES;
2803 }
2804}
2805
2806} // namespace Kinoko::Kart
#define KCL_ANY
@ COL_TYPE_MOVING_WATER
Koopa Cape and DS Yoshi Falls.
@ COL_TYPE_STICKY_ROAD
Player sticks if within 200 units (rBC stairs).
@ COL_TYPE_SPECIAL_WALL
Various other wall types, determined by variant.
#define KCL_TYPE_BIT(x)
#define KCL_NONE
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
#define ASSERT(e)
Definition Logger.hh:25
A 3 x 4 matrix.
Definition Matrix.hh:10
constexpr void setAxisRotation(f32 angle, const EGG::Vector3f &axis)
Rotates the matrix about an axis.
Definition Matrix.hh:216
constexpr Vector3f multVector(const Vector3f &vec) const
Multiplies a vector by a matrix.
Definition Matrix.hh:261
constexpr Vector3f multVector33(const Vector3f &vec) const
Multiplies a 3x3 matrix by a vector.
Definition Matrix.hh:285
constexpr void makeOrthonormalBasis(const Vector3f &forward, const Vector3f &up)
Sets a 3x3 orthonormal basis for a local coordinate system.
Definition Matrix.hh:190
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:424
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:391
constexpr bool onAllBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:413
constexpr TBitFlagExt< N, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:367
constexpr TBitFlagExt< N, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:356
constexpr bool offAnyBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:446
bool checkSphereFullPush(f32 radius, const EGG::Vector3f &v0, const EGG::Vector3f &v1, KCLTypeMask flags, CollisionInfo *pInfo, KCLTypeMask *pFlagsOut, u32 timeOffset)
static CollisionDirector * Instance()
static ObjectDirector * Instance()
KartItem & kartItem(size_t idx)
static ItemDirector * Instance()
bool start(Action action)
Starts an action.
Definition KartAction.cc:55
bool calc()
Computes the current frame's boost multiplier, acceleration, and speed limit.
Definition KartBoost.cc:38
bool activate(Type type, s16 frames)
Starts/restarts a boost of the given type.
Definition KartBoost.cc:21
f32 acceleration() const
Definition KartBoost.hh:35
void activateOob(bool detachCamera, Field::KCLTypeMask *mask, bool somethingCPU, bool somethingBullet)
KartPullPath & pullPath()
void setExtVel(const EGG::Vector3f &v)
const EGG::Vector3f & totalForce() const
const EGG::Vector3f & extVel() const
void setAngVel2(const EGG::Vector3f &v)
const EGG::Vector3f & movingObjVel() const
void setNoGravity(bool isSet)
void setTotalForce(const EGG::Vector3f &v)
void setTop(const EGG::Vector3f &v)
const EGG::Vector3f & angVel2() const
void setAngVel0(const EGG::Vector3f &v)
const EGG::Vector3f & pos() const
const EGG::Quatf & fullRot() const
void setStabilizationFactor(f32 val)
void setMovingObjVel(const EGG::Vector3f &v)
const EGG::Vector3f & angVel0() const
void addForce(const EGG::Vector3f &pos)
void setIntVel(const EGG::Vector3f &v)
void setPos(const EGG::Vector3f &pos)
void setMovingRoadVel(const EGG::Vector3f &v)
void setFullRot(const EGG::Quatf &q)
void applyWrenchScaled(const EGG::Vector3f &p, const EGG::Vector3f &f, f32 scale)
Applies a force linearly and rotationally to the kart.
void setGravity(f32 gravity)
void setMainRot(const EGG::Quatf &q)
const EGG::Quatf & mainRot() const
void setKillExtVelY(bool isSet)
void setTop_(const EGG::Vector3f &v)
static consteval f32 TerminalVelocity()
bool isBoostRampEnabled() const
Definition KartJump.hh:67
TrickType type() const
Definition KartJump.hh:71
SurfaceVariant variant() const
Definition KartJump.hh:75
void tryStart(const EGG::Vector3f &left)
Definition KartJump.cc:89
void createSubsystems(const KartParam::Stats &stats) override
Definition KartMove.cc:2505
f32 m_wheelieRot
X-axis rotation from wheeling.
Definition KartMove.hh:560
const TurningParameters * m_turningParams
Inside/outside drifting bike turn info.
Definition KartMove.hh:566
void init(bool b1, bool b2) override
Definition KartMove.cc:2648
virtual void startWheelie()
STAGE 1+ - Sets the wheelie bit flag and some wheelie-related variables.
Definition KartMove.cc:2483
f32 m_wheelieRotDec
The wheelie rotation decrementor, used after a wheelie has ended.
Definition KartMove.hh:564
virtual void cancelWheelie()
Clears the wheelie bit flag and resets the rotation decrement.
Definition KartMove.cc:2498
void tryStartWheelie()
STAGE 1+ - Every frame, checks player input to see if we should start or stop a wheelie.
Definition KartMove.cc:2782
f32 m_leanRotInc
The incrementor for leaning rotation.
Definition KartMove.hh:559
void onWallCollision() override
Called when you collide with a wall. All it does for bikes is cancel wheelies.
Definition KartMove.cc:2740
void calcMtCharge() override
Every frame during a drift, calculates MT charge based on player input.
Definition KartMove.cc:2747
f32 m_maxWheelieRot
The maximum wheelie rotation.
Definition KartMove.hh:561
void onHop() override
Virtual function that just cancels wheelies when you hop.
Definition KartMove.cc:2730
void setTurnParams() override
On init, sets the bike's lean rotation cap and increment.In addition to setting the lean rotation cap...
Definition KartMove.cc:2624
u32 m_wheelieFrames
Tracks wheelie duration and cancels the wheelie after 180 frames.
Definition KartMove.hh:562
bool canWheelie() const override
Checks if the kart is going fast enough to wheelie.
Definition KartMove.hh:548
f32 m_leanRot
Z-axis rotation of the bike from leaning.
Definition KartMove.hh:557
s16 m_wheelieCooldown
The number of frames before another wheelie can start.
Definition KartMove.hh:563
void calcWheelie() override
STAGE 1+ - Every frame, checks player input for wheelies and computes wheelie rotation.
Definition KartMove.cc:2669
void calcVehicleRotation(f32) override
Every frame, calculates rotation, EV, and angular velocity for the bike.
Definition KartMove.cc:2514
f32 m_leanRotCap
The maximum leaning rotation.
Definition KartMove.hh:558
void initOob() override
Definition KartMove.cc:2775
u16 m_floorCollisionCount
The number of tires colliding with the floor.
Definition KartMove.hh:419
f32 m_processedSpeed
Offset 0x28. It's only ever just a copy of m_speed.
Definition KartMove.hh:397
bool calcPreDrift()
Each frame, checks for hop or slipdrift. Computes drift direction based on player input.
Definition KartMove.cc:845
DriftState m_driftState
Definition KartMove.hh:426
void calcWallCollisionStart(f32 param_2)
If we started to collide with a wall this frame, applies rotation.
Definition KartMove.cc:1618
void deactivateShock(bool resetSpeed)
Definition KartMove.cc:2329
s32 m_hopStickX
A ternary for the direction of our hop, 0 if still neutral hopping.
Definition KartMove.hh:420
s16 m_offroadInvincibility
How many frames until the player is affected by offroad.
Definition KartMove.hh:434
const JumpPadProperties * m_jumpPadProperties
Definition KartMove.hh:453
EGG::Vector3f m_scale
Normally the unit vector, but may vary due to crush animations.
Definition KartMove.hh:440
virtual void onWallCollision()
Definition KartMove.hh:108
EGG::Vector3f m_smoothedForward
Definition KartMove.hh:407
f32 m_kclWheelSpeedFactor
The slowest speed multiplier of each wheel's floor collision.
Definition KartMove.hh:417
f32 m_divingRot
Induces x-axis angular velocity based on up/down stick input.
Definition KartMove.hh:424
f32 m_speed
Current speed, restricted to the soft speed limit.
Definition KartMove.hh:395
void calcDisableBackwardsAccel()
Computes the current cooldown duration between braking and reversing.
Definition KartMove.cc:771
void calcStandstillBoostRot()
STAGE Computes the x-component of angular velocity based on the kart's speed.
Definition KartMove.cc:1685
f32 m_lastSpeed
Last frame's speed, cached to calculate angular velocity.
Definition KartMove.hh:396
void calc()
Each frame, calculates the kart's movement.
Definition KartMove.cc:296
f32 m_outsideDriftBonus
Added to angular velocity when outside drifting.
Definition KartMove.hh:429
f32 m_hopPosY
Relative position as the result of a hop. Starts at 0.
Definition KartMove.hh:463
EGG::Vector3f m_smoothedUp
A smoothed up vector, mostly used after significant airtime.
Definition KartMove.hh:401
DrivingDirection m_drivingDirection
Current state of driver's direction.
Definition KartMove.hh:470
f32 calcWallCollisionSpeedFactor(f32 &f1)
Every frame, computes a speed scalar if we are colliding with a wall.
Definition KartMove.cc:1585
void calcOffroad()
Each frame, computes rotation and speed scalars from the floor KCL.
Definition KartMove.cc:680
s16 m_backwardsAllowCounter
Tracks the 15f delay before reversing.
Definition KartMove.hh:471
virtual bool canHop() const
Definition KartMove.hh:126
f32 m_outsideDriftAngle
The facing angle of an outward-drifting vehicle.
Definition KartMove.hh:410
void calcSsmt()
Calculates standstill mini-turbo components, if applicable.
Definition KartMove.cc:788
s16 m_bumpTimer
Set when a SmallBump collision occurs.
Definition KartMove.hh:469
f32 m_acceleration
Captures the acceleration from player input and boosts.
Definition KartMove.hh:399
s16 m_ssmtLeewayTimer
Frames to forgive letting go of A before clearing SSMT charge.
Definition KartMove.hh:436
void applyForce(f32 force, const EGG::Vector3f &hitDir, bool stop)
Definition KartMove.cc:1834
s32 getAppliedHopStickX() const
Factors in vehicle speed to retrieve our hop direction and magnitude.
Definition KartMove.hh:253
virtual void onHop()
Definition KartMove.hh:106
void calcManualDrift()
Each frame, handles hopping, drifting, and mini-turbos.
Definition KartMove.cc:1014
void setInitialPhysicsValues(const EGG::Vector3f &position, const EGG::Vector3f &angles)
Initializes the kart's position and rotation. Calls tire suspension initializers.
Definition KartMove.cc:258
EGG::Vector3f m_lastDir
m_speed from the previous frame but with signed magnitude.
Definition KartMove.hh:405
void calcVehicleSpeed()
Every frame, computes speed based on acceleration and any active boosts.
Definition KartMove.cc:1294
f32 m_weightedTurn
Magnitude+direction of stick input, factoring in the kart's stats.
Definition KartMove.hh:439
s32 m_hopFrame
A timer that can prevent subsequent hops until reset.
Definition KartMove.hh:421
void calcSpecialFloor()
Every frame, calculates any boost resulting from a boost panel.
Definition KartMove.cc:522
virtual void init(bool b1, bool b2)
Definition KartMove.cc:143
void calcDive()
Responds to player input to handle up/down kart tilt mid-air.
Definition KartMove.cc:1726
f32 m_softSpeedLimit
Base speed + boosts + wheelies, restricted to the hard speed limit.
Definition KartMove.hh:394
s16 m_timeInRespawn
The number of frames elapsed after position snap from respawn.
Definition KartMove.hh:465
EGG::Vector3f m_cannonProgress
Definition KartMove.hh:461
u16 m_smtCharge
A value between 0 and 300 representing current SMT charge.
Definition KartMove.hh:428
f32 m_kclWheelRotFactor
The slowest rotation multiplier of each wheel's floor collision.
Definition KartMove.hh:418
KartBurnout m_burnout
Manages the state of start boost burnout.
Definition KartMove.hh:477
EGG::Vector3f m_outsideDriftLastDir
Used to compute the next m_outsideDriftAngle.
Definition KartMove.hh:412
void applyShrink(u16 timer)
Definition KartMove.cc:2296
void activateCrush(u16 timer)
Definition KartMove.cc:2261
void calcAutoDrift()
Each frame, handles automatic transmission drifting.
Definition KartMove.cc:959
void applyStartBoost(s16 frames)
Definition KartMove.cc:2125
void startManualDrift()
Called when the player lands from a drift hop, or to start a slipdrift.
Definition KartMove.cc:1096
void calcSsmtStart()
Calculates whether we are starting a standstill mini-turbo.
Definition KartMove.cc:1787
void clearOffroadInvincibility()
Definition KartMove.cc:947
const EGG::Vector3f & smoothedUp() const
Definition KartMove.hh:277
f32 m_speedDragMultiplier
After 5 frames of airtime, this causes speed to slowly decay.
Definition KartMove.hh:400
EGG::Vector3f m_dirDiff
Definition KartMove.hh:408
void controlOutsideDriftAngle()
Every frame, handles mini-turbo charging and outside drifting bike rotation.
Definition KartMove.cc:1164
f32 m_jumpPadMinSpeed
Snaps the player to a minimum speed when first touching a jump pad.
Definition KartMove.hh:449
f32 m_totalScale
[Unused] Always 1.0f
Definition KartMove.hh:441
EGG::Vector3f m_cannonEntryOfs
Definition KartMove.hh:459
EGG::Vector3f m_hopDir
Used for outward drift. Tracks the forward vector of our rotation.
Definition KartMove.hh:423
const EGG::Vector3f & scale() const
Definition KartMove.hh:269
f32 calcSlerpRate(f32 scale, const EGG::Quatf &from, const EGG::Quatf &to) const
Definition KartMove.cc:1827
s16 m_ssmtCharge
Increments every frame up to 75 when charging stand-still MT.
Definition KartMove.hh:435
virtual void hop()
Initializes hop information, resets upwards EV and clears upwards force.
Definition KartMove.cc:1963
u16 m_mtCharge
A value between 0 and 270 representing current MT charge.
Definition KartMove.hh:427
virtual void calcMtCharge()
Every frame during a drift, calculates MT/SMT charge based on player input.
Definition KartMove.cc:1898
void activateBoost(KartBoost::Type type, s16 frames)
Definition KartMove.cc:2118
u16 m_mushroomBoostTimer
Number of frames until the mushroom boost runs out.
Definition KartMove.hh:444
f32 m_kclRotFactor
Float between 0-1 that scales the player's turning radius on offroad.
Definition KartMove.hh:416
bool canStartDrift() const
Definition KartMove.hh:144
bool calcZipperCollision(f32 radius, f32 scale, EGG::Vector3f &pos, EGG::Vector3f &upLocal, const EGG::Vector3f &prevPos, Field::CollisionInfo *colInfo, Field::KCLTypeMask *maskOut, Field::KCLTypeMask flags) const
Definition KartMove.cc:1816
void calcAcceleration()
Every frame, applies acceleration to the kart's internal velocity.
Definition KartMove.cc:1433
f32 m_rawTurn
Float in range [-1, 1]. Represents stick magnitude + direction.
Definition KartMove.hh:479
s16 m_respawnPostLandTimer
Counts up to 4 if not accelerating after respawn landing.
Definition KartMove.hh:467
virtual f32 getWheelieSoftSpeedLimitBonus() const
Returns the % speed boost from wheelies. For karts, this is always 0.
Definition KartMove.hh:116
void calcRotCannon(const EGG::Vector3f &forward)
Definition KartMove.cc:2438
void releaseMt()
Stops charging a mini-turbo, and applies boost if charged.
Definition KartMove.cc:1138
u16 m_crushTimer
Number of frames until player will be uncrushed.
Definition KartMove.hh:447
EGG::Vector3f m_cannonOrthog
Definition KartMove.hh:460
f32 m_speedRatio
The ratio between current speed and the player's base speed stat.
Definition KartMove.hh:414
void calcAirtimeTop()
Calculates rotation of the bike due to excessive airtime.
Definition KartMove.cc:497
EGG::Vector3f m_up
Vector perpendicular to the floor, pointing upwards.
Definition KartMove.hh:402
virtual void initOob()
Definition KartMove.cc:1951
void setScale(const EGG::Vector3f &v)
Definition KartMove.hh:223
f32 m_hopVelY
Relative velocity due to a hop. Starts at 10 and decreases with gravity.
Definition KartMove.hh:462
KartScale * m_kartScale
Manages scaling due to TF stompers and MH cars.
Definition KartMove.hh:476
@ DriftReset
Set when a wall bonk should cancel your drift.
Definition KartMove.hh:362
@ SsmtCharged
Set after holding a stand-still mini-turbo for 75 frames.
Definition KartMove.hh:363
@ TrickableSurface
Set when driving on a trickable surface.
Definition KartMove.hh:366
@ SsmtLeeway
If set, activates SSMT when not pressing A or B.
Definition KartMove.hh:365
@ WallBounce
Set when our speed loss from wall collision is > 30.0f.
Definition KartMove.hh:367
@ Respawned
Set when Lakitu lets go of the player, cleared when landing.
Definition KartMove.hh:361
f32 m_speedRatioCapped
m_speedRatio but capped at 1.0f.
Definition KartMove.hh:413
void calcRotation()
Every frame, calculates kart rotation based on player input.
Definition KartMove.cc:1197
KartHalfPipe * m_halfPipe
Pertains to zipper physics.
Definition KartMove.hh:475
EGG::Vector3f m_cannonEntryPos
Definition KartMove.hh:458
f32 m_hopGravity
Always main gravity (-1.3f).
Definition KartMove.hh:464
const EGG::Vector3f & dir() const
Definition KartMove.hh:293
void calcOffroadInvincibility()
Checks a timer to see if we are still ignoring offroad slowdown.
Definition KartMove.cc:2181
f32 m_kclSpeedFactor
Float between 0-1 that scales the player's speed on offroad.
Definition KartMove.hh:415
virtual void createSubsystems(const KartParam::Stats &stats)
Definition KartMove.cc:67
f32 calcVehicleAcceleration() const
Every frame, computes acceleration based off the character/vehicle stats.
Definition KartMove.cc:1399
f32 acceleration() const
Definition KartMove.hh:265
s16 m_ssmtDisableAccelTimer
Counter that tracks delay before starting to reverse.
Definition KartMove.hh:437
virtual void clear()
Definition KartMove.cc:238
virtual void calcTurn()
Each frame, looks at player input and kart stats. Saves turn-related info.
Definition KartMove.cc:76
void calcMushroomBoost()
Checks a timer to see if we are still boosting from a mushroom.
Definition KartMove.cc:2197
s16 m_respawnPreLandTimer
Counts down from 4 when pressing A before landing from respawn.
Definition KartMove.hh:466
virtual void calcVehicleRotation(f32 turn)
Every frame, calculates rotation, EV, and angular velocity for the kart.
Definition KartMove.cc:1853
void resetDriftManual()
Clears drift state. Called when touching ground and drift is canceled.
Definition KartMove.cc:887
void tryStartBoostRamp()
Sets offroad invincibility and enables the ramp boost bitfield flag.
Definition KartMove.cc:2003
void setOffroadInvincibility(s16 timer)
Ignores offroad KCL collision for a set amount of time.
Definition KartMove.cc:2170
void tryStartJumpPad()
Applies calculations to start interacting with a jump pad.
Definition KartMove.cc:2021
static constexpr f32 MINIMUM_DRIFT_THRESOLD
Definition KartMove.hh:481
virtual void setTurnParams()
Definition KartMove.cc:124
EGG::Vector3f m_vel1Dir
Definition KartMove.hh:406
virtual void calcWheelie()
Definition KartMove.hh:43
EGG::Vector3f m_dir
Definition KartMove.hh:404
@ WaitingForBackwards
Holding reverse but waiting on a 15 frame delay.
Definition KartMove.hh:375
f32 m_hardSpeedLimit
Absolute speed cap. It's 120, unless you're in a bullet (140).
Definition KartMove.hh:398
f32 m_realTurn
The "true" turn magnitude. Equal to m_weightedTurn unless drifting.
Definition KartMove.hh:438
const DriftingParameters * m_driftingParams
Drift-type-specific parameters.
Definition KartMove.hh:478
f32 m_baseSpeed
The speed associated with the current character/vehicle stats.
Definition KartMove.hh:393
const EGG::Vector3f & up() const
Definition KartMove.hh:281
EGG::Vector3f m_landingDir
Definition KartMove.hh:403
EGG::Vector3f m_hopUp
The up vector when hopping.
Definition KartMove.hh:422
Field::KCLTypeMask wallKclType() const
const EGG::Vector3f & extVel() const
const EGG::Vector3f & prevPos() const
const EGG::Vector3f & componentZAxis() const
const EGG::Vector3f & angVel2() const
void setInertiaScale(const EGG::Vector3f &scale)
const EGG::Vector3f & pos() const
std::pair< EGG::Vector3f, EGG::Vector3f > getCannonPosRot()
EGG::Vector3f bodyUp() const
Returns the second column of the rotation matrix, which is the "up" direction.
const System::KPad * inputs() const
const EGG::Vector3f & componentYAxis() const
void setPos(const EGG::Vector3f &pos)
const EGG::Vector3f & intVel() const
const EGG::Vector3f & wheelEdgePos(u16 idx) const
KartSuspension * suspension(u16 suspIdx)
EGG::Vector3f bodyFront() const
Returns the third column of the rotation matrix, which is the facing vector.
const EGG::Quatf & mainRot() const
const EGG::Vector3f & velocity() const
const EGG::Vector3f & wheelPos(u16 idx) const
void setRot(const EGG::Quatf &q)
const EGG::Vector3f & componentXAxis() const
const Stats & stats() const
Definition KartParam.hh:173
void composeExtraRot(const EGG::Quatf &rot)
void setPos(const EGG::Vector3f &pos)
void setVelocity(const EGG::Vector3f &vel)
void startShrink(s32 unk)
Definition KartScale.cc:89
const EGG::Vector3f & sizeScale() const
Definition KartScale.hh:22
const EGG::Vector3f & pressScale() const
Definition KartScale.hh:26
void endShrink(s32 unk)
Definition KartScale.cc:100
const EGG::Vector3f & top() const
Definition KartState.hh:81
f32 startBoostCharge() const
Definition KartState.hh:89
s32 jumpPadVariant() const
Definition KartState.hh:65
bool isDrifting() const
Definition KartState.hh:53
static CourseMap * Instance()
Definition CourseMap.hh:184
MapdataCannonPoint * getCannonPoint(u16 i) const
Definition CourseMap.hh:61
const RaceInputState & currentState() const
MapdataJugemPoint * jugemPoint() const
static RaceManager * Instance()
EGG core library.
Definition Allocator.hh:5
void egg_delete(const T *ptr)
Definition Heap.hh:154
T * egg_new(Args &&...args)
Definition Heap.hh:148
Pertains to kart-related functionality.
static constexpr std::array< CannonParameter, 3 > CANNON_PARAMETERS
Definition KartMove.cc:36
@ Wheelie
Set while we are in a wheelie (even during the countdown).
Definition Status.hh:40
@ HopStart
Set if m_bDriftInput was toggled on this frame.
Definition Status.hh:20
@ RejectRoad
Collision which causes a change in the player's pos and rot.
Definition Status.hh:64
@ DisableBackwardsAccel
Enforces a 20f delay when reversing after charging SSMT.
Definition Status.hh:58
@ HalfPipeRamp
Set while colliding with zipper KCL.
Definition Status.hh:51
@ SoftWallPush
Tracks whether we are being pushed by a soft wall or HWG.
Definition Status.hh:84
@ Boost
Set while in a boost.
Definition Status.hh:32
@ BoostOffroadInvincibility
Set if we should ignore offroad slowdown this frame.
Definition Status.hh:50
@ HWG
Set when "Horizontal Wall Glitch" is active.
Definition Status.hh:86
@ ZipperTrick
Set while tricking mid-air from a zipper.
Definition Status.hh:57
@ SlipdriftCharge
Currently in a drift w/ automatic.
Definition Status.hh:38
@ Hop
Set while we are in a drift hop. Clears when we land.
Definition Status.hh:31
@ MushroomBoost
Set while we are in a mushroom boost.
Definition Status.hh:37
@ SoftWallUnlockRotation
Set when we are in "Barrel Roll" state.
Definition Status.hh:85
@ StickyRoad
Like the rBC stairs.
Definition Status.hh:29
@ StickLeft
Set on left stick input. Mutually exclusive to m_bStickRight.
Definition Status.hh:26
@ RespawnKillY
Set while respawning to cap external velocity at 0.
Definition Status.hh:59
@ VehicleBodyFloorCollision
Set if the vehicle body is colliding with the floor.
Definition Status.hh:23
@ RejectRoadTrigger
e.g. DK Summit ending, and Maple Treeway side walls.
Definition Status.hh:65
@ GroundStart
Set first frame landing from airtime.
Definition Status.hh:22
@ Accelerate
Accel button is pressed.
Definition Status.hh:9
@ StickRight
Set on right stick input. Mutually exclusive to m_bStickLeft.
Definition Status.hh:35
@ ActionMidZipper
Set when we enter an action while mid-air from a zipper.
Definition Status.hh:88
@ DriftInput
A "fake" button, normally set if you meet the speed requirement to hop.
Definition Status.hh:15
@ AirtimeOver20
Set after 20 frames of airtime, resets on landing.
Definition Status.hh:28
@ ZipperBoost
Set when boosting after landing from a zipper.
Definition Status.hh:55
@ DriftManual
Currently in a drift w/ manual.
Definition Status.hh:16
@ OverZipper
Set while mid-air from a zipper.
Definition Status.hh:52
@ ChargingSSMT
Tracks whether we are charging a stand-still mini-turbo.
Definition Status.hh:63
@ AccelerateStart
Set if m_bAccelerate was toggled on this frame.
Definition Status.hh:21
@ Burnout
Set during a burnout on race start.
Definition Status.hh:60
@ WallCollisionStart
Set if we have just started colliding with a wall.
Definition Status.hh:27
@ AnyWheelCollision
Set when any wheel is touching floor collision.
Definition Status.hh:24
@ AutoDrift
True if auto transmission, false if manual.
Definition Status.hh:93
@ Wall3Collision
Set when colliding with wall KCL COL_TYPE_WALL_2.
Definition Status.hh:18
@ TouchingGround
Set when any part of the vehicle is colliding with floor KCL.
Definition Status.hh:30
@ ZipperInvisibleWall
Set when colliding with invisible wall above a zipper.
Definition Status.hh:54
@ BeforeRespawn
Set on respawn collision, cleared on position snap.
Definition Status.hh:17
@ WallCollision
Set if we are colliding with a wall.
Definition Status.hh:19
@ BikeSideStuntTrick
A side StuntTrick with a bike.
Definition KartJump.hh:25
float f32
Definition Memory.hh:21
int16_t s16
Definition Memory.hh:12
uint16_t u16
Definition Memory.hh:17
int32_t s32
Definition Memory.hh:13
uint32_t u32
Definition Memory.hh:18
constexpr void setZero()
Definition BoundBox.hh:46
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
constexpr f32 dot(const Quatf &q) const
Computes .
Definition Quat.hh:205
constexpr void setAxisRotation(f32 angle, const EGG::Vector3f &axis)
Set the quat given angle and axis.
Definition Quat.hh:211
constexpr void makeVectorRotation(const Vector3f &from, const Vector3f &to)
Captures rotation between two vectors.
Definition Quat.hh:119
constexpr void normalise()
Scales the quaternion to a unit length.
Definition Quat.hh:107
constexpr Vector3f rotateVector(const Vector3f &vec) const
Rotates a vector based on the quat.
Definition Quat.hh:139
static constexpr Quatf FromRPY(const EGG::Vector3f &rpy)
Definition Quat.hh:243
constexpr Quatf multSwap(const Vector3f &vec) const
Definition Quat.hh:220
constexpr Quatf slerpTo(const Quatf &q1, f32 t) const
Performs spherical linear interpolation.
Definition Quat.hh:168
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:153
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:120
constexpr TBitFlag< T, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:74
constexpr TBitFlag< T, E > & changeBit(bool on, Es... es)
Changes the state of the corresponding bits for the provided enum values.
Definition BitFlag.hh:97
constexpr void makeAllZero()
Resets all the bits to zero.
Definition BitFlag.hh:246
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:85
A 3D float vector.
Definition Vector.hh:108
constexpr f32 squaredLength() const
The dot product between the vector and itself.
Definition Vector.hh:202
static const Vector3f zero
Definition Vector.hh:386
static const Vector3f ey
Definition Vector.hh:388
static const Vector3f ez
Definition Vector.hh:388
static const Vector3f inf
Definition Vector.hh:389
constexpr void set(f32 val)
Definition Vector.hh:126
constexpr f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
Definition Vector.hh:207
constexpr f32 length() const
The square root of the vector's dot product.
Definition Vector.hh:212
constexpr Vector3f proj(const Vector3f &rhs) const
The projection of this vector onto rhs.
Definition Vector.hh:224
constexpr f32 normalise()
Normalizes the vector and returns the original length.
Definition Vector.hh:279
constexpr void setZero()
Definition Vector.hh:122
constexpr Vector3f cross(const Vector3f &rhs) const
Definition Vector.hh:197
static const Vector3f ex
Definition Vector.hh:388
constexpr Vector3f rej(const Vector3f &rhs) const
The rejection of this vector onto rhs.
Definition Vector.hh:230
constexpr Vector3f perpInPlane(const EGG::Vector3f &rhs, bool normalise) const
Calculates the orthogonal vector, based on the plane defined by this vector and rhs.
Definition Vector.hh:347
constexpr std::pair< Vector3f, Vector3f > projAndRej(const Vector3f &rhs) const
Definition Vector.hh:235
Stores information pertaining to a collision.
EGG::Vector3f tangentOff
The net "push out" vector.
EGG::Vector3f floorNrm
Colliding floor's up vector.
EGG::BoundBox3f bbox
Bounding box of "push out" vectors.
Information about the current collision and its properties.
Various character/vehicle-related handling and speed stats.
Definition KartParam.hh:84
std::array< f32, 32 > kclRot
Rotation scalars, indexed using KCL attributes.
Definition KartParam.hh:130
f32 driftAutomaticTightness
Affects turn radius when automatic drifting.
Definition KartParam.hh:124
std::array< f32, 32 > kclSpeed
Speed multipliers, indexed using KCL attributes.
Definition KartParam.hh:129
f32 driftReactivity
A weight applied to turn radius when drifting.
Definition KartParam.hh:125
std::array< f32, 2 > accelerationDriftA
Definition KartParam.hh:118
f32 speed
Base full speed of the character/vehicle combo.
Definition KartParam.hh:113
f32 handlingReactivity
A weight applied to turn radius when not drifting.
Definition KartParam.hh:122
std::array< f32, 1 > accelerationDriftT
Definition KartParam.hh:119
f32 driftManualTightness
Affects turn radius when manual drifting.
Definition KartParam.hh:123
std::array< f32, 4 > accelerationStandardA
Definition KartParam.hh:116
std::array< f32, 3 > accelerationStandardT
Definition KartParam.hh:117
u32 miniTurbo
The framecount duration of a charged mini-turbo.
Definition KartParam.hh:128