A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartMove.cc
1#include "KartMove.hh"
2
3#include "game/kart/KartCollide.hh"
4#include "game/kart/KartDynamics.hh"
5#include "game/kart/KartJump.hh"
6#include "game/kart/KartParam.hh"
7#include "game/kart/KartPhysics.hh"
8#include "game/kart/KartScale.hh"
9#include "game/kart/KartSub.hh"
10#include "game/kart/KartSuspension.hh"
11
12#include "game/field/CollisionDirector.hh"
14
15#include "game/item/ItemDirector.hh"
16#include "game/item/KartItem.hh"
17
18#include "game/system/CourseMap.hh"
19#include "game/system/RaceManager.hh"
20#include "game/system/map/MapdataCannonPoint.hh"
21#include "game/system/map/MapdataJugemPoint.hh"
22
23#include <egg/math/Math.hh>
24#include <egg/math/Quat.hh>
25
26namespace Kart {
27
29 f32 speed;
30 f32 height;
31 f32 decelFactor;
32 f32 endDecel;
33};
34
35static constexpr std::array<CannonParameter, 3> CANNON_PARAMETERS = {{
36 {500.0f, 0.0f, 6000.0f, -1.0f},
37 {500.0f, 5000.0f, 6000.0f, -1.0f},
38 {120.0f, 2000.0f, 1000.0f, 45.0f},
39}};
40
42KartMove::KartMove() : m_smoothedUp(EGG::Vector3f::ey), m_scale(1.0f, 1.0f, 1.0f) {
43 m_totalScale = 1.0f;
44 m_hitboxScale = 1.0f;
45 m_padType.makeAllZero();
46 m_flags.makeAllZero();
47 m_jump = nullptr;
48}
49
51KartMove::~KartMove() {
52 delete m_jump;
53 delete m_halfPipe;
54 delete m_kartScale;
55}
56
58void KartMove::createSubsystems() {
59 m_jump = new KartJump(this);
60 m_halfPipe = new KartHalfPipe();
61 m_kartScale = new KartScale();
62}
63
68 m_realTurn = 0.0f;
69 m_rawTurn = 0.0f;
70
71 if (state()->isInAction() || state()->isCannonStart() || state()->isInCannon() ||
72 state()->isOverZipper()) {
73 return;
74 }
75
76 if (state()->isBeforeRespawn()) {
77 return;
78 }
79
80 if (!state()->isHop() || m_hopStickX == 0) {
81 m_rawTurn = -state()->stickX();
82 if (state()->isJumpPadMushroomCollision()) {
83 m_rawTurn *= 0.35f;
84 } else if (state()->isAirtimeOver20()) {
85 m_rawTurn *= 0.01f;
86 }
87 } else {
88 m_rawTurn = static_cast<f32>(m_hopStickX);
89 }
90
91 f32 reactivity;
92 if (state()->isDrifting()) {
93 reactivity = param()->stats().driftReactivity;
94 } else {
95 reactivity = param()->stats().handlingReactivity;
96 }
97
98 m_weightedTurn = m_rawTurn * reactivity + m_weightedTurn * (1.0f - reactivity);
99 m_weightedTurn = std::max(-1.0f, std::min(1.0f, m_weightedTurn));
100
102
103 if (!state()->isDrifting()) {
104 return;
105 }
106
107 m_realTurn = (m_weightedTurn + static_cast<f32>(m_hopStickX)) * 0.5f;
108 m_realTurn = m_realTurn * 0.8f + 0.2f * static_cast<f32>(m_hopStickX);
109 m_realTurn = std::max(-1.0f, std::min(1.0f, m_realTurn));
110}
111
113void KartMove::setTurnParams() {
114 static constexpr std::array<DriftingParameters, 3> DRIFTING_PARAMS_ARRAY = {{
115 {10.0f, 0.5f, 0.5f, 1.0f},
116 {10.0f, 0.5f, 0.5f, 0.2f},
117 {10.0f, 0.22f, 0.5f, 0.2f},
118 }};
119
120 init(false, false);
121 m_dir = bodyFront();
122 m_lastDir = m_dir;
123 m_vel1Dir = m_dir;
124 m_landingDir = m_dir;
125 m_outsideDriftLastDir = m_dir;
126 m_driftingParams = &DRIFTING_PARAMS_ARRAY[static_cast<u32>(param()->stats().driftType)];
127 m_kartScale->reset();
128}
129
131void KartMove::init(bool b1, bool b2) {
132 m_lastSpeed = 0.0f;
133 m_baseSpeed = param()->stats().speed;
134 m_jumpPadSoftSpeedLimit = m_softSpeedLimit = param()->stats().speed;
135 m_speed = 0.0f;
136 setKartSpeedLimit();
137 m_acceleration = 0.0f;
139 m_up = EGG::Vector3f::ey;
140 m_smoothedUp = EGG::Vector3f::ey;
141 m_vel1Dir = EGG::Vector3f::ez;
142 m_lastDir = EGG::Vector3f::ez;
143 m_dir = EGG::Vector3f::ez;
144 m_landingDir = EGG::Vector3f::ez;
145 m_dirDiff = EGG::Vector3f::zero;
146 m_hasLandingDir = false;
147 m_outsideDriftAngle = 0.0f;
148 m_landingAngle = 0.0f;
149 m_outsideDriftLastDir = EGG::Vector3f::ez;
150 m_speedRatio = 0.0f;
151 m_speedRatioCapped = 0.0f;
152 m_kclSpeedFactor = 1.0f;
153 m_kclRotFactor = 1.0f;
155 m_kclWheelRotFactor = 1.0f;
156
157 if (!b2) {
159 }
160
161 m_hopStickX = 0;
162 m_hopFrame = 0;
163 m_hopUp = EGG::Vector3f::ey;
164 m_hopDir = EGG::Vector3f::ez;
165 m_divingRot = 0.0f;
166 m_standStillBoostRot = 0.0f;
167 m_driftState = DriftState::NotDrifting;
168 m_smtCharge = 0;
169 m_mtCharge = 0;
170 m_outsideDriftBonus = 0.0f;
171 m_boost.reset();
172 m_zipperBoostTimer = 0;
173 m_zipperBoostMax = 0;
174 m_reject.reset();
176 m_ssmtCharge = 0;
179 m_nonZipperAirtime = 0;
180 m_realTurn = 0.0f;
181 m_weightedTurn = 0.0f;
182
183 if (!b1) {
184 m_scale.set(1.0f);
185 m_totalScale = 1.0f;
186 m_hitboxScale = 1.0f;
188 m_crushTimer = 0;
189 }
190
191 m_jumpPadMinSpeed = 0.0f;
192 m_jumpPadMaxSpeed = 0.0f;
193 m_jumpPadBoostMultiplier = 0.0f;
194 m_jumpPadProperties = nullptr;
195 m_rampBoost = 0;
196 m_autoDriftAngle = 0.0f;
197 m_autoDriftStartFrameCounter = 0;
198
199 m_cannonEntryOfsLength = 0.0f;
200 m_cannonEntryPos.setZero();
201 m_cannonEntryOfs.setZero();
202 m_cannonOrthog.setZero();
203 m_cannonProgress.setZero();
204
205 m_hopVelY = 0.0f;
206 m_hopPosY = 0.0f;
207 m_hopGravity = 0.0f;
208 m_timeInRespawn = 0;
211 m_respawnTimer = 0;
212 m_drivingDirection = DrivingDirection::Forwards;
213 m_padType.makeAllZero();
214 m_flags.makeAllZero();
215 m_jump->reset();
216 m_halfPipe->reset();
217 m_rawTurn = 0.0f;
218}
219
221void KartMove::clear() {
222 if (state()->isOverZipper()) {
223 state()->setActionMidZipper(true);
224 }
225
226 clearBoost();
227 clearJumpPad();
228 clearRampBoost();
229 clearZipperBoost();
230 clearSsmt();
231 clearOffroadInvincibility();
232 m_halfPipe->end(false);
233 m_jump->end();
234 clearRejectRoad();
235}
236
240 EGG::Quatf quaternion = EGG::Quatf::FromRPY(angles * DEG2RAD);
241 EGG::Vector3f newPos = position;
243 Field::KCLTypeMask kcl_flags = KCL_NONE;
244
245 bool bColliding = Field::CollisionDirector::Instance()->checkSphereFullPush(100.0f, newPos,
246 EGG::Vector3f::inf, KCL_ANY, &info, &kcl_flags, 0);
247
248 if (bColliding && (kcl_flags & KCL_TYPE_FLOOR)) {
249 newPos = newPos + info.tangentOff + (info.floorNrm * -100.0f);
250 newPos += info.floorNrm * bsp().initialYPos;
251 }
252
253 setPos(newPos);
254 setRot(quaternion);
255
256 sub()->initPhysicsValues();
257
258 physics()->setPos(pos());
259 physics()->setVelocity(dynamics()->velocity());
260
261 m_landingDir = bodyFront();
262 m_dir = bodyFront();
263 m_up = bodyUp();
264 dynamics()->setTop(m_up);
265
266 for (u16 tireIdx = 0; tireIdx < suspCount(); ++tireIdx) {
267 suspension(tireIdx)->setInitialState();
268 }
269}
270
277 if (state()->isInRespawn()) {
278 calcInRespawn();
279 return;
280 }
281
282 dynamics()->resetInternalVelocity();
283 m_burnout.calc();
285 m_halfPipe->calc();
286 calcTop();
287 tryEndJumpPad();
288 calcRespawnBoost();
290 m_jump->calc();
292 calcDirs();
293 calcStickyRoad();
294 calcOffroad();
295 calcTurn();
296
297 if (!state()->isAutoDrift()) {
299 }
300
301 calcWheelie();
302 calcSsmt();
303 calcBoost();
305 calcZipperBoost();
306 calcCrushed();
307 calcScale();
308
309 if (state()->isInCannon()) {
310 calcCannon();
311 }
312
316 calcRotation();
317}
318
320void KartMove::calcRespawnStart() {
321 constexpr float RESPAWN_HEIGHT = 700.0f;
322
323 const auto *jugemPoint = System::RaceManager::Instance()->jugemPoint();
324 const EGG::Vector3f &jugemPos = jugemPoint->pos();
325 const EGG::Vector3f &jugemRot = jugemPoint->rot();
326
327 EGG::Vector3f respawnPos = jugemPos;
328 respawnPos.y += RESPAWN_HEIGHT;
329 EGG::Vector3f respawnRot = EGG::Vector3f(0.0f, jugemRot.y, 0.0f);
330
331 setInitialPhysicsValues(respawnPos, respawnRot);
332
333 Item::ItemDirector::Instance()->kartItem(0).clear();
334
335 state()->setTriggerRespawn(false);
336 state()->setInRespawn(true);
337}
338
340void KartMove::calcInRespawn() {
341 constexpr f32 LAKITU_VELOCITY = 1.5f;
342 constexpr u16 RESPAWN_DURATION = 110;
343
344 if (!state()->isInRespawn()) {
345 return;
346 }
347
348 EGG::Vector3f newPos = pos();
349 newPos.y -= LAKITU_VELOCITY;
350 dynamics()->setPos(newPos);
351 dynamics()->setNoGravity(true);
352
353 if (++m_timeInRespawn > RESPAWN_DURATION) {
354 state()->setInRespawn(false);
355 state()->setAfterRespawn(true);
356 state()->setRespawnKillY(true);
357 m_timeInRespawn = 0;
358 m_flags.setBit(eFlags::Respawned);
359 dynamics()->setNoGravity(false);
360 }
361}
362
364void KartMove::calcRespawnBoost() {
365 constexpr s16 RESPAWN_BOOST_DURATION = 30;
366 constexpr s16 RESPAWN_BOOST_INPUT_LENIENCY = 4;
367
368 if (state()->isAfterRespawn()) {
369 if (state()->isTouchingGround()) {
370 if (m_respawnPreLandTimer > 0) {
371 if (!state()->isBeforeRespawn() && !state()->isInAction()) {
372 activateBoost(KartBoost::Type::AllMt, RESPAWN_BOOST_DURATION);
373 m_respawnTimer = RESPAWN_BOOST_DURATION;
374 }
375 } else {
376 m_respawnPostLandTimer = RESPAWN_BOOST_INPUT_LENIENCY;
377 }
378
379 state()->setAfterRespawn(false);
381 }
382
384
385 if (m_flags.onBit(eFlags::Respawned) && state()->isAccelerateStart()) {
386 m_respawnPreLandTimer = RESPAWN_BOOST_INPUT_LENIENCY;
388 }
389 } else {
390 if (m_respawnPostLandTimer > 0) {
391 if (state()->isAccelerateStart()) {
392 if (!state()->isBeforeRespawn() && !state()->isInAction()) {
393 activateBoost(KartBoost::Type::AllMt, RESPAWN_BOOST_DURATION);
394 m_respawnTimer = RESPAWN_BOOST_DURATION;
395 }
396
398 }
399
401 } else {
402 state()->setRespawnKillY(false);
403 }
404 }
405
406 m_respawnTimer = std::max(0, m_respawnTimer - 1);
407}
408
410void KartMove::calcTop() {
411 f32 stabilizationFactor = 0.1f;
412 m_hasLandingDir = false;
413 EGG::Vector3f inputTop = state()->top();
414
415 if (state()->isGroundStart() && m_nonZipperAirtime >= 3) {
416 m_smoothedUp = inputTop;
417 m_up = inputTop;
418 m_landingDir = m_dir.perpInPlane(m_smoothedUp, true);
419 m_dirDiff = m_landingDir.proj(m_landingDir);
420 m_hasLandingDir = true;
421 } else {
422 if (state()->isHop() && m_hopPosY > 0.0f) {
423 stabilizationFactor = m_driftingParams->stabilizationFactor;
424 } else if (state()->isTouchingGround()) {
425 if ((m_flags.onBit(eFlags::TrickableSurface) || state()->trickableTimer() > 0) &&
426 inputTop.dot(m_dir) > 0.0f && m_speed > 50.0f &&
427 collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::NotTrickable)) {
428 inputTop = m_up;
429 } else {
430 m_up = inputTop;
431 }
432
433 f32 scalar = 0.8f;
434
435 if (state()->isHalfPipeRamp() ||
436 (!state()->isBoost() && !state()->isRampBoost() && !state()->isWheelie() &&
437 !state()->isOverZipper() &&
438 (!state()->isZipperBoost() || m_zipperBoostTimer > 15))) {
439 f32 topDotZ = 0.8f - 6.0f * (EGG::Mathf::abs(inputTop.dot(componentZAxis())));
440 scalar = std::min(0.8f, std::max(0.3f, topDotZ));
441 }
442
443 m_smoothedUp += (inputTop - m_smoothedUp) * scalar;
445
446 f32 bodyDotFront = bodyFront().dot(m_smoothedUp);
447
448 if (bodyDotFront < -0.1f) {
449 stabilizationFactor += std::min(0.2f, EGG::Mathf::abs(bodyDotFront) * 0.5f);
450 }
451
452 if (collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::BoostRamp)) {
453 stabilizationFactor = 0.4f;
454 }
455 } else {
457 }
458 }
459
460 dynamics()->setStabilizationFactor(stabilizationFactor);
461
462 m_nonZipperAirtime = state()->isOverZipper() ? 0 : state()->airtime();
463 m_flags.changeBit(collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::Trickable),
465}
466
470 if (state()->isOverZipper() || !state()->isAirtimeOver20()) {
471 return;
472 }
473
474 if (m_smoothedUp.y <= 0.99f) {
475 m_smoothedUp += (EGG::Vector3f::ey - m_smoothedUp) * 0.03f;
477 } else {
478 m_smoothedUp = EGG::Vector3f::ey;
479 }
480
481 if (m_up.y <= 0.99f) {
482 m_up += (EGG::Vector3f::ey - m_up) * 0.03f;
483 m_up.normalise();
484 } else {
485 m_up = EGG::Vector3f::ey;
486 }
487}
488
493 const auto *raceMgr = System::RaceManager::Instance();
494 if (!raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
495 return;
496 }
497
498 if (m_padType.onBit(ePadType::BoostPanel)) {
499 tryStartBoostPanel();
500 }
501
502 if (m_padType.onBit(ePadType::BoostRamp)) {
504 }
505
506 if (m_padType.onBit(ePadType::JumpPad)) {
508 }
509
510 m_padType.makeAllZero();
511}
512
514void KartMove::calcDirs() {
515 EGG::Vector3f right = dynamics()->mainRot().rotateVector(EGG::Vector3f::ex);
516 EGG::Vector3f local_88 = right.cross(m_smoothedUp);
517 local_88.normalise();
518 m_flags.setBit(eFlags::LaunchBoost);
519
520 if (!state()->isInATrick() && !state()->isOverZipper() &&
521 (((state()->isTouchingGround() || !state()->isRampBoost() ||
522 !m_jump->isBoostRampEnabled()) &&
523 !state()->isJumpPad() && state()->airtime() <= 5) ||
524 state()->isJumpPadMushroomCollision() || state()->isNoSparkInvisibleWall())) {
525 if (state()->isHop()) {
526 local_88 = m_hopDir;
527 }
528
529 EGG::Matrix34f mat;
530 mat.setAxisRotation(DEG2RAD * (m_autoDriftAngle + m_outsideDriftAngle + m_landingAngle),
532 EGG::Vector3f local_b8 = mat.multVector(local_88);
533 local_b8 = local_b8.perpInPlane(m_smoothedUp, true);
534
535 EGG::Vector3f dirDiff = local_b8 - m_dir;
536
537 if (dirDiff.squaredLength() <= std::numeric_limits<f32>::epsilon()) {
538 m_dir = local_b8;
539 m_dirDiff.setZero();
540 } else {
541 EGG::Vector3f origDirCross = m_dir.cross(local_b8);
542 m_dirDiff += m_kclRotFactor * dirDiff;
543 m_dir += m_dirDiff;
544 m_dir.normalise();
545 m_dirDiff *= 0.1f;
546 EGG::Vector3f newDirCross = m_dir.cross(local_b8);
547
548 if (origDirCross.dot(newDirCross) < 0.0f) {
549 m_dir = local_b8;
550 m_dirDiff.setZero();
551 }
552 }
553
554 m_vel1Dir = m_dir.perpInPlane(m_smoothedUp, true);
555 m_flags.resetBit(eFlags::LaunchBoost);
556 } else {
557 m_vel1Dir = m_dir;
558 }
559
560 if (!state()->isOverZipper()) {
561 m_jump->tryStart(m_smoothedUp.cross(m_dir));
562 }
563
564 if (m_hasLandingDir) {
565 f32 dot = m_dir.dot(m_landingDir);
566 EGG::Vector3f cross = m_dir.cross(m_landingDir);
567 f32 crossDot = cross.length();
568 f32 angle = EGG::Mathf::atan2(crossDot, dot);
569 angle = EGG::Mathf::abs(angle);
570
571 f32 fVar4 = 1.0f;
572 if (cross.dot(m_smoothedUp) < 0.0f) {
573 fVar4 = -1.0f;
574 }
575
576 m_landingAngle += (angle * RAD2DEG) * fVar4;
577 }
578
579 if (m_landingAngle <= 0.0f) {
580 if (m_landingAngle < 0.0f) {
581 m_landingAngle = std::min(0.0f, m_landingAngle + 2.0f);
582 }
583 } else {
584 m_landingAngle = std::max(0.0f, m_landingAngle - 2.0f);
585 }
586}
587
589void KartMove::calcStickyRoad() {
590 constexpr f32 STICKY_RADIUS = 200.0f;
591 constexpr Field::KCLTypeMask STICKY_MASK =
593
594 if (state()->isOverZipper()) {
595 state()->setStickyRoad(false);
596 return;
597 }
598
599 if ((!state()->isStickyRoad() &&
600 collide()->surfaceFlags().offBit(KartCollide::eSurfaceFlags::Trickable)) ||
601 EGG::Mathf::abs(m_speed) <= 20.0f) {
602 return;
603 }
604
605 EGG::Vector3f pos = dynamics()->pos();
606 EGG::Vector3f vel = dynamics()->movingObjVel() + m_speed * m_vel1Dir;
607 EGG::Vector3f down = -STICKY_RADIUS * componentYAxis();
608 Field::CollisionInfo colInfo;
609 colInfo.bbox.setZero();
610 Field::KCLTypeMask kcl_flags = KCL_NONE;
611 bool stickyRoad = false;
612
613 for (size_t i = 0; i < 3; ++i) {
614 EGG::Vector3f newPos = pos + vel;
615 if (Field::CollisionDirector::Instance()->checkSphereFull(STICKY_RADIUS, newPos,
616 EGG::Vector3f::inf, STICKY_MASK, &colInfo, &kcl_flags, 0)) {
617 m_vel1Dir = m_vel1Dir.perpInPlane(colInfo.floorNrm, true);
618 dynamics()->setMovingObjVel(dynamics()->movingObjVel().rej(colInfo.floorNrm));
619 stickyRoad = true;
620
621 break;
622 }
623 vel *= 0.5f;
624 pos += -STICKY_RADIUS * componentYAxis();
625 }
626
627 if (!stickyRoad) {
628 state()->setStickyRoad(false);
629 }
630}
631
636 if (state()->isBoostOffroadInvincibility()) {
637 m_kclSpeedFactor = 1.0f;
638 m_kclRotFactor = param()->stats().kclRot[0];
639 } else {
640 bool anyWheel = state()->isAnyWheelCollision();
641 if (anyWheel) {
645 }
646
647 if (state()->isVehicleBodyFloorCollision()) {
648 const CollisionData &colData = collisionData();
649 if (anyWheel) {
650 if (colData.speedFactor < m_kclWheelSpeedFactor) {
651 m_kclSpeedFactor = colData.speedFactor;
652 }
653 m_kclRotFactor = (m_kclWheelRotFactor + colData.rotFactor) /
654 static_cast<f32>(m_floorCollisionCount + 1);
655 } else {
656 m_kclSpeedFactor = colData.speedFactor;
657 m_kclRotFactor = colData.rotFactor;
658 }
659 }
660 }
661}
662
664void KartMove::calcBoost() {
665 if (m_boost.calc()) {
666 state()->setAccelerate(true);
667 } else {
668 state()->setBoost(false);
669 }
670
671 calcRampBoost();
672}
673
675void KartMove::calcRampBoost() {
676 if (!state()->isRampBoost()) {
677 return;
678 }
679
680 state()->setAccelerate(true);
681 if (--m_rampBoost < 1) {
682 m_rampBoost = 0;
683 state()->setRampBoost(false);
684 }
685}
686
691 if (!state()->isDisableBackwardsAccel()) {
692 return;
693 }
694
695 if (--m_ssmtDisableAccelTimer < 0 ||
696 (m_flags.offBit(eFlags::SsmtLeeway) && !state()->isBrake())) {
697 state()->setDisableBackwardsAccel(false);
699 }
700}
701
706 constexpr s16 MAX_SSMT_CHARGE = 75;
707 constexpr s16 SSMT_BOOST_FRAMES = 30;
708 constexpr s16 LEEWAY_FRAMES = 1;
709 constexpr s16 DISABLE_ACCEL_FRAMES = 20;
710
712
713 if (state()->isChargingSsmt()) {
714 if (++m_ssmtCharge > MAX_SSMT_CHARGE) {
715 m_ssmtCharge = MAX_SSMT_CHARGE;
718 }
719
720 return;
721 }
722
723 m_ssmtCharge = 0;
724
725 if (m_flags.offBit(eFlags::SsmtCharged)) {
726 return;
727 }
728
729 if (m_flags.onBit(eFlags::SsmtLeeway)) {
730 if (--m_ssmtLeewayTimer < 0) {
733 m_ssmtDisableAccelTimer = DISABLE_ACCEL_FRAMES;
734 state()->setDisableBackwardsAccel(true);
735 } else {
736 if (!state()->isAccelerate() && !state()->isBrake()) {
737 activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
740 }
741 }
742 } else {
743 if (state()->isAccelerate() && !state()->isBrake()) {
744 activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
747 } else {
748 m_ssmtLeewayTimer = LEEWAY_FRAMES;
749 m_flags.setBit(eFlags::SsmtLeeway);
750 state()->setDisableBackwardsAccel(true);
751 m_ssmtDisableAccelTimer = LEEWAY_FRAMES;
752 }
753 }
754}
755
761 if (!state()->isTouchingGround() && !state()->isHop() && !state()->isDriftManual()) {
762 if (state()->isStickLeft() || state()->isStickRight()) {
763 if (!state()->isDriftInput()) {
764 state()->setSlipdriftCharge(false);
765 } else if (!state()->isSlipdriftCharge()) {
766 if (m_hopStickX == 0) {
767 if (state()->isStickRight()) {
768 m_hopStickX = -1;
769 } else if (state()->isStickLeft()) {
770 m_hopStickX = 1;
771 }
772 state()->setSlipdriftCharge(true);
773 onHop();
774 }
775 }
776 }
777 }
778
779 if (state()->isHop()) {
780 if (m_hopStickX == 0) {
781 if (state()->isStickRight()) {
782 m_hopStickX = -1;
783 } else if (state()->isStickLeft()) {
784 m_hopStickX = 1;
785 }
786 }
787 if (m_hopFrame < 3) {
788 ++m_hopFrame;
789 }
790 } else if (state()->isSlipdriftCharge()) {
791 m_hopFrame = 0;
792 }
793
794 return state()->isHop() || state()->isSlipdriftCharge();
795}
796
801 m_hopStickX = 0;
802 m_hopFrame = 0;
803 state()->setHop(false);
804 state()->setDriftManual(false);
805 m_driftState = DriftState::NotDrifting;
806 m_smtCharge = 0;
807 m_mtCharge = 0;
808}
809
814 m_outsideDriftAngle = 0.0f;
815 m_hopStickX = 0;
816 m_hopFrame = 0;
817 m_driftState = DriftState::NotDrifting;
818 m_smtCharge = 0;
819 m_mtCharge = 0;
820 m_outsideDriftBonus = 0.0f;
821 state()->setHop(false);
822 state()->setSlipdriftCharge(false);
823 state()->setDriftManual(false);
824 state()->setDriftAuto(false);
825 m_autoDriftAngle = 0.0f;
826 m_hopStickX = 0;
827 m_autoDriftStartFrameCounter = 0;
828}
829
831void KartMove::clearJumpPad() {
832 m_jumpPadMinSpeed = 0.0f;
833 state()->setJumpPad(false);
834}
835
837void KartMove::clearRampBoost() {
838 m_rampBoost = 0;
839 state()->setRampBoost(false);
840}
841
843void KartMove::clearZipperBoost() {
844 m_zipperBoostTimer = 0;
845 state()->setZipperBoost(false);
846}
847
849void KartMove::clearBoost() {
850 m_boost.resetActive();
851 state()->setBoost(false);
852}
853
855void KartMove::clearSsmt() {
856 m_ssmtCharge = 0;
860}
861
863void KartMove::clearOffroadInvincibility() {
865 state()->setBoostOffroadInvincibility(false);
866}
867
868void KartMove::clearRejectRoad() {
869 state()->setRejectRoadTrigger(false);
870 state()->setNoSparkInvisibleWall(false);
871}
872
877 constexpr s16 AUTO_DRIFT_START_DELAY = 12;
878
879 if (!state()->isAutoDrift()) {
880 return;
881 }
882
883 if (canStartDrift() && !state()->isOverZipper() && !state()->isRejectRoadTrigger() &&
884 !state()->isWheelie() && EGG::Mathf::abs(state()->stickX()) > 0.85f) {
885 m_autoDriftStartFrameCounter =
886 std::min<s16>(AUTO_DRIFT_START_DELAY, m_autoDriftStartFrameCounter + 1);
887 } else {
888 m_autoDriftStartFrameCounter = 0;
889 }
890
891 if (m_autoDriftStartFrameCounter >= AUTO_DRIFT_START_DELAY) {
892 state()->setDriftAuto(true);
893
894 if (state()->isTouchingGround()) {
895 if (state()->stickX() < 0.0f) {
896 m_hopStickX = 1;
897 m_autoDriftAngle -= 30.0f * param()->stats().driftAutomaticTightness;
898
899 } else {
900 m_hopStickX = -1;
901 m_autoDriftAngle += 30.0f * param()->stats().driftAutomaticTightness;
902 }
903 }
904
905 f32 halfTarget = 0.5f * param()->stats().driftOutsideTargetAngle;
906 m_autoDriftAngle = std::min(halfTarget, std::max(-halfTarget, m_autoDriftAngle));
907 } else {
908 state()->setDriftAuto(false);
909 m_hopStickX = 0;
910
911 if (m_autoDriftAngle > 0.0f) {
912 m_autoDriftAngle =
913 std::max(0.0f, m_autoDriftAngle - param()->stats().driftOutsideDecrement);
914 } else {
915 m_autoDriftAngle =
916 std::min(0.0f, m_autoDriftAngle + param()->stats().driftOutsideDecrement);
917 }
918 }
919
920 EGG::Quatf angleAxis;
921 angleAxis.setAxisRotation(-m_autoDriftAngle * DEG2RAD, m_up);
922 physics()->composeExtraRot(angleAxis);
923}
924
929 bool isHopping = calcPreDrift();
930
931 if (!state()->isOverZipper()) {
932 const EGG::Vector3f rotZ = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
933
934 if (!state()->isTouchingGround() &&
935 param()->stats().driftType != KartParam::Stats::DriftType::Inside_Drift_Bike &&
936 !state()->isJumpPadMushroomCollision() &&
937 (state()->isDriftManual() || state()->isSlipdriftCharge()) &&
938 m_flags.onBit(eFlags::LaunchBoost)) {
939 const EGG::Vector3f up = dynamics()->mainRot().rotateVector(EGG::Vector3f::ey);
941
942 if (driftRej.normalise() != 0.0f) {
943 f32 rejCrossDirMag = driftRej.cross(rotZ).length();
944 f32 angle = EGG::Mathf::atan2(rejCrossDirMag, driftRej.dot(rotZ));
945 f32 sign = 1.0f;
946 if ((rotZ.z * (rotZ.x - driftRej.x)) - (rotZ.x * (rotZ.z - driftRej.z)) > 0.0f) {
947 sign = -1.0f;
948 }
949
950 m_outsideDriftAngle += angle * RAD2DEG * sign;
951 }
952 }
953
955 }
956
957 // TODO: Is this backwards/inverted?
958 if (((!state()->isHop() || m_hopFrame < 3) && !state()->isSlipdriftCharge()) ||
959 (state()->isInAction() || !state()->isTouchingGround())) {
960 if (canHop()) {
961 hop();
962 isHopping = true;
963 }
964 } else {
966 isHopping = false;
967 }
968
970
971 if (!state()->isDriftManual()) {
972 if (!isHopping && state()->isTouchingGround()) {
974
975 if (action()->flags().offBit(KartAction::eFlags::Rotating) || m_speed <= 20.0f) {
976 f32 driftAngleDecr = param()->stats().driftOutsideDecrement;
977 if (m_outsideDriftAngle > 0.0f) {
978 m_outsideDriftAngle = std::max(0.0f, m_outsideDriftAngle - driftAngleDecr);
979 } else if (m_outsideDriftAngle < 0.0f) {
980 m_outsideDriftAngle = std::min(0.0f, m_outsideDriftAngle + driftAngleDecr);
981 }
982 }
983 }
984 } else {
985 if (!state()->isOverZipper() &&
986 (!state()->isDriftInput() || !state()->isAccelerate() || state()->isInAction() ||
987 state()->isRejectRoadTrigger() || state()->isWall3Collision() ||
988 state()->isWallCollision() || !canStartDrift())) {
989 if (canStartDrift()) {
990 releaseMt();
991 }
992
994 m_flags.setBit(eFlags::DriftReset);
995 } else {
997 }
998 }
999}
1000
1005 constexpr f32 OUTSIDE_DRIFT_BONUS = 0.5f;
1006
1007 const auto &stats = param()->stats();
1008
1009 if (stats.driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1010 f32 driftAngle = 0.0f;
1011
1012 if (state()->isHop()) {
1013 const EGG::Vector3f rotZ = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1014 EGG::Vector3f rotRej = rotZ.rej(m_hopUp);
1015
1016 if (rotRej.normalise() != 0.0f) {
1017 const EGG::Vector3f hopCrossRot = m_hopDir.cross(rotRej);
1018 driftAngle =
1019 EGG::Mathf::atan2(hopCrossRot.length(), m_hopDir.dot(rotRej)) * RAD2DEG;
1020 }
1021 }
1022
1023 m_outsideDriftAngle += driftAngle * static_cast<f32>(-m_hopStickX);
1024 m_outsideDriftAngle = std::max(-60.0f, std::min(60.0f, m_outsideDriftAngle));
1025 }
1026
1027 state()->setHop(false);
1028 state()->setSlipdriftCharge(false);
1029
1030 if (!state()->isDriftInput()) {
1031 return;
1032 }
1033
1034 if (getAppliedHopStickX() == 0) {
1035 return;
1036 }
1037
1038 state()->setDriftManual(true);
1039 state()->setHop(false);
1040 m_driftState = DriftState::ChargingMt;
1041 m_outsideDriftBonus = OUTSIDE_DRIFT_BONUS * (m_speedRatioCapped * stats.driftManualTightness);
1042}
1043
1048 constexpr f32 SMT_LENGTH_FACTOR = 3.0f;
1049
1050 if (m_driftState < DriftState::ChargedMt || state()->isBrake()) {
1051 m_driftState = DriftState::NotDrifting;
1052 return;
1053 }
1054
1055 u16 mtLength = param()->stats().miniTurbo;
1056
1057 if (m_driftState == DriftState::ChargedSmt) {
1058 mtLength *= SMT_LENGTH_FACTOR;
1059 }
1060
1061 if (!state()->isBeforeRespawn() && !state()->isInAction()) {
1062 activateBoost(KartBoost::Type::AllMt, mtLength);
1063 }
1064
1065 m_driftState = DriftState::NotDrifting;
1066}
1067
1072 if (state()->airtime() > 5) {
1073 return;
1074 }
1075
1076 if (param()->stats().driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1077 if (m_hopStickX == -1) {
1078 f32 angle = m_outsideDriftAngle;
1079 f32 targetAngle = param()->stats().driftOutsideTargetAngle;
1080 if (angle > targetAngle) {
1081 m_outsideDriftAngle = std::max(m_outsideDriftAngle - 2.0f, targetAngle);
1082 } else if (angle < targetAngle) {
1083 m_outsideDriftAngle += 150.0f * param()->stats().driftManualTightness;
1084 m_outsideDriftAngle = std::min(m_outsideDriftAngle, targetAngle);
1085 }
1086 } else if (m_hopStickX == 1) {
1087 f32 angle = m_outsideDriftAngle;
1088 f32 targetAngle = -param()->stats().driftOutsideTargetAngle;
1089 if (targetAngle > angle) {
1090 m_outsideDriftAngle = std::min(m_outsideDriftAngle + 2.0f, targetAngle);
1091 } else if (targetAngle < angle) {
1092 m_outsideDriftAngle -= 150.0f * param()->stats().driftManualTightness;
1093 m_outsideDriftAngle = std::max(m_outsideDriftAngle, targetAngle);
1094 }
1095 }
1096 }
1097
1098 calcMtCharge();
1099}
1100
1105 f32 turn;
1106 bool drifting = state()->isDrifting() && !state()->isJumpPadMushroomCollision();
1107 bool autoDrift = state()->isAutoDrift();
1108 const auto &stats = param()->stats();
1109
1110 if (drifting) {
1111 turn = autoDrift ? stats.driftAutomaticTightness : stats.driftManualTightness;
1112 } else {
1113 turn = autoDrift ? stats.handlingAutomaticTightness : stats.handlingManualTightness;
1114 }
1115
1116 if (drifting && stats.driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1117 m_outsideDriftBonus *= 0.99f;
1118 turn += m_outsideDriftBonus;
1119 }
1120
1121 bool forwards = true;
1122 if (state()->isBrake() && m_speed <= 0.0f) {
1123 forwards = false;
1124 }
1125
1126 turn *= m_realTurn;
1127 if (state()->isChargingSsmt()) {
1128 turn = m_realTurn * 0.04f;
1129 } else {
1130 if (state()->isHop() && m_hopPosY > 0.0f) {
1131 turn *= 1.4f;
1132 }
1133
1134 if (!drifting) {
1135 bool noTurn = false;
1136 if (!state()->isWallCollision() && !state()->isWall3Collision() &&
1137 EGG::Mathf::abs(m_speed) < 1.0f) {
1138 if (!(state()->isHop() && m_hopPosY > 0.0f)) {
1139 turn = 0.0f;
1140 noTurn = true;
1141 }
1142 }
1143 if (forwards && !noTurn) {
1144 if (m_speed >= 20.0f) {
1145 turn *= 0.5f;
1146 if (m_speed < 70.0f) {
1147 turn += (1.0f - (m_speed - 20.0f) / 50.0f) * turn;
1148 }
1149 } else {
1150 turn = (turn * 0.4f) + (m_speed / 20.0f) * (turn * 0.6f);
1151 }
1152 }
1153 }
1154
1155 if (!forwards) {
1156 turn = -turn;
1157 }
1158
1159 if (state()->isZipperBoost() && !state()->isDriftManual()) {
1160 turn *= 2.0f;
1161 }
1162
1163 f32 stickX = EGG::Mathf::abs(state()->stickX());
1164 if (autoDrift && stickX > 0.3f) {
1165 f32 stickScalar = (stickX - 0.3f) / 0.7f;
1166 stickX = drifting ? 0.2f : 0.5f;
1167 turn += stickScalar * (turn * stickX * m_speedRatioCapped);
1168 }
1169 }
1170
1171 if (!state()->isInAction() && !state()->isZipperTrick()) {
1172 if (!state()->isTouchingGround()) {
1173 if (state()->isRampBoost() && m_jump->isBoostRampEnabled()) {
1174 turn = 0.0f;
1175 } else if (!state()->isJumpPadMushroomCollision()) {
1176 u32 airtime = state()->airtime();
1177 if (airtime >= 70) {
1178 turn = 0.0f;
1179 } else if (airtime >= 30) {
1180 turn = std::max(0.0f, turn * (1.0f - (airtime - 30) * 0.025f));
1181 }
1182 }
1183 }
1184
1185 const EGG::Vector3f forward = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1186 f32 angle = EGG::Mathf::atan2(forward.cross(m_dir).length(), forward.dot(m_dir));
1187 angle = EGG::Mathf::abs(angle) * RAD2DEG;
1188
1189 if (angle > 60.0f) {
1190 turn *= std::max(0.0f, 1.0f - (angle - 60.0f) / 40.0f);
1191 }
1192 }
1193
1194 calcVehicleRotation(turn);
1195}
1196
1201 const auto *raceMgr = System::RaceManager::Instance();
1202 if (raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
1203 f32 speedFix = dynamics()->speedFix();
1204 if (state()->isInAction() ||
1205 ((state()->isWallCollisionStart() || state()->wallBonkTimer() == 0 ||
1206 EGG::Mathf::abs(speedFix) >= 3.0f) &&
1207 !state()->isDriftManual())) {
1208 m_speed += speedFix;
1209 }
1210 }
1211
1212 if (m_speed < -20.0f) {
1213 m_speed += 0.5f;
1214 }
1215
1216 m_acceleration = 0.0f;
1217 m_speedDragMultiplier = 1.0f;
1218
1219 if (state()->isInAction()) {
1220 action()->calcVehicleSpeed();
1221 return;
1222 }
1223
1224 if ((state()->isSomethingWallCollision() && state()->isTouchingGround() &&
1225 !state()->isAnyWheelCollision()) ||
1226 !state()->isTouchingGround() || state()->isChargingSsmt()) {
1227 if (state()->isRampBoost() && state()->airtime() < 4) {
1228 m_acceleration = 7.0f;
1229 } else {
1230 if (state()->isJumpPad() && !state()->isAccelerate()) {
1231 m_speedDragMultiplier = 0.99f;
1232 } else {
1233 if (state()->isOverZipper()) {
1234 m_speedDragMultiplier = 0.999f;
1235 } else {
1236 if (state()->airtime() > 5) {
1237 m_speedDragMultiplier = 0.999f;
1238 }
1239 }
1240 }
1242 }
1243
1244 } else if (state()->isBoost()) {
1245 m_acceleration = m_boost.acceleration();
1246 } else {
1247 if (!state()->isJumpPad() && !state()->isRampBoost()) {
1248 if (state()->isAccelerate()) {
1249 m_acceleration = state()->isHalfPipeRamp() ? 5.0f : calcVehicleAcceleration();
1250 } else {
1251 if (!state()->isBrake() || state()->isDisableBackwardsAccel() ||
1252 state()->isSomethingWallCollision()) {
1253 m_speed *= m_speed > 0.0f ? 0.98f : 0.95f;
1254 } else if (m_drivingDirection == DrivingDirection::Braking) {
1255 m_acceleration = -1.5f;
1257 if (++m_backwardsAllowCounter > 15) {
1258 m_drivingDirection = DrivingDirection::Backwards;
1259 }
1260 } else if (m_drivingDirection == DrivingDirection::Backwards) {
1261 m_acceleration = -2.0f;
1262 }
1263 }
1264
1265 if (!state()->isBoost() && !state()->isDriftManual() && !state()->isAutoDrift()) {
1266 const auto &stats = param()->stats();
1267
1268 f32 x = 1.0f - EGG::Mathf::abs(m_weightedTurn) * m_speedRatioCapped;
1269 m_speed *= stats.turningSpeed + (1.0f - stats.turningSpeed) * x;
1270 }
1271 } else {
1272 m_acceleration = 7.0f;
1273 }
1274 }
1275}
1276
1280 f32 vel = 0.0f;
1281 f32 initialVel = 1.0f - m_smoothedUp.y;
1282 if (EGG::Mathf::abs(m_speed) < 30.0f && m_smoothedUp.y > 0.0f && initialVel > 0.0f) {
1283 initialVel = std::min(initialVel * 2.0f, 2.0f);
1284 vel += initialVel;
1285 vel *= std::min(0.5f, std::max(-0.5f, -bodyFront().y));
1286 }
1287 m_speed += vel;
1288}
1289
1294 f32 ratio = m_speed / m_softSpeedLimit;
1295 if (ratio < 0.0f) {
1296 return 1.0f;
1297 }
1298
1299 std::span<const f32> as;
1300 std::span<const f32> ts;
1301 if (state()->isDrifting()) {
1302 as = param()->stats().accelerationDriftA;
1303 ts = param()->stats().accelerationDriftT;
1304 } else {
1305 as = param()->stats().accelerationStandardA;
1306 ts = param()->stats().accelerationStandardT;
1307 }
1308
1309 size_t i = 0;
1310 f32 acceleration = 0.0f;
1311 f32 t_curr = 0.0f;
1312 for (; i < ts.size(); ++i) {
1313 if (ratio < ts[i]) {
1314 acceleration = as[i] + ((as[i + 1] - as[i]) / (ts[i] - t_curr)) * (ratio - t_curr);
1315 break;
1316 }
1317
1318 t_curr = ts[i];
1319 }
1320
1321 return i < ts.size() ? acceleration : as.back();
1322}
1323
1328 constexpr f32 ROTATION_SCALAR_NORMAL = 0.5f;
1329 constexpr f32 ROTATION_SCALAR_MIDAIR = 0.2f;
1330 constexpr f32 ROTATION_SCALAR_BOOST_RAMP = 4.0f;
1331 constexpr f32 OOB_SLOWDOWN_RATE = 0.95f;
1332 constexpr f32 TERMINAL_VELOCITY = 90.0f;
1333
1335
1336 dynamics()->setKillExtVelY(state()->isRespawnKillY());
1337
1338 if (state()->isBurnout()) {
1339 m_speed = 0.0f;
1340 } else {
1341 if (m_acceleration < 0.0f) {
1342 if (m_speed < -20.0f) {
1343 m_acceleration = 0.0f;
1344 } else {
1345 if (m_speed + m_acceleration <= -20.0f) {
1346 m_acceleration = -20.0f - m_speed;
1347 }
1348 }
1349 }
1350
1352 }
1353
1354 if (state()->isBeforeRespawn()) {
1355 m_speed *= OOB_SLOWDOWN_RATE;
1356 } else {
1357 if (state()->isChargingSsmt()) {
1358 m_speed *= 0.8f;
1359 } else {
1360 if (m_drivingDirection == DrivingDirection::Braking && m_speed < 0.0f) {
1361 m_speed = 0.0f;
1364 }
1365 }
1366 }
1367
1368 f32 speedLimit = state()->isJumpPad() ? m_jumpPadMaxSpeed : m_baseSpeed;
1369 const f32 boostMultiplier = m_boost.multiplier();
1370 const f32 boostSpdLimit = m_boost.speedLimit();
1371 m_jumpPadBoostMultiplier = boostMultiplier;
1372
1373 f32 crushMultiplier = state()->isCrushed() ? 0.7f : 1.0f;
1374 f32 wheelieBonus = boostMultiplier + getWheelieSoftSpeedLimitBonus();
1375 speedLimit *= state()->isJumpPadFixedSpeed() ?
1376 1.0f :
1377 crushMultiplier * (wheelieBonus * m_kclSpeedFactor);
1378
1379 bool ignoreCrushSpeed = state()->isRampBoost() || state()->isZipperInvisibleWall() ||
1380 state()->isOverZipper() || state()->isHalfPipeRamp();
1381 f32 boostSpeed = ignoreCrushSpeed ? 1.0f : crushMultiplier;
1382 boostSpeed *= boostSpdLimit * m_kclSpeedFactor;
1383
1384 if (!state()->isJumpPad() && boostSpeed > 0.0f && boostSpeed > speedLimit) {
1385 speedLimit = boostSpeed;
1386 }
1387
1388 m_jumpPadSoftSpeedLimit = boostSpdLimit * m_kclSpeedFactor;
1389
1390 if (state()->isRampBoost()) {
1391 speedLimit = std::max(speedLimit, 100.0f);
1392 }
1393
1394 m_lastDir = (m_speed > 0.0f) ? 1.0f * m_dir : -1.0f * m_dir;
1395
1396 f32 local_c8 = 1.0f;
1397 speedLimit *= calcWallCollisionSpeedFactor(local_c8);
1398
1399 if (!state()->isWallCollision() && !state()->isWall3Collision()) {
1400 m_softSpeedLimit = std::max(m_softSpeedLimit - 3.0f, speedLimit);
1401 } else {
1402 m_softSpeedLimit = speedLimit;
1403 }
1404
1406
1407 m_speed = std::min(m_softSpeedLimit, std::max(-m_softSpeedLimit, m_speed));
1408
1409 if (state()->isJumpPad()) {
1410 m_speed = std::max(m_speed, m_jumpPadMinSpeed);
1411 }
1412
1413 calcWallCollisionStart(local_c8);
1414
1415 m_speedRatio = EGG::Mathf::abs(m_speed / m_baseSpeed);
1416 m_speedRatioCapped = std::min(1.0f, m_speedRatio);
1417
1418 EGG::Vector3f crossVec = m_smoothedUp.cross(m_dir);
1419 if (m_speed < 0.0f) {
1420 crossVec = -crossVec;
1421 }
1422
1423 f32 rotationScalar = ROTATION_SCALAR_NORMAL;
1424 if (collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::BoostRamp)) {
1425 rotationScalar = ROTATION_SCALAR_BOOST_RAMP;
1426 } else if (!state()->isTouchingGround()) {
1427 rotationScalar = ROTATION_SCALAR_MIDAIR;
1428 }
1429
1430 EGG::Matrix34f local_90;
1431 local_90.setAxisRotation(rotationScalar * DEG2RAD, crossVec);
1432 m_vel1Dir = local_90.multVector33(m_vel1Dir);
1433
1434 const auto *raceMgr = System::RaceManager::Instance();
1435 if (!state()->isInAction() && !state()->isDisableBackwardsAccel() &&
1436 state()->isTouchingGround() && !state()->isAccelerate() &&
1437 raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
1439 }
1440
1442 EGG::Vector3f nextSpeed = m_speed * m_vel1Dir;
1443
1444 f32 maxSpeedY = state()->isOverZipper() ? KartHalfPipe::TerminalVelocity() : TERMINAL_VELOCITY;
1445 nextSpeed.y = std::min(nextSpeed.y, maxSpeedY);
1446
1447 dynamics()->setIntVel(dynamics()->intVel() + nextSpeed);
1448
1449 if (state()->isTouchingGround() && !state()->isDriftManual() && !state()->isHop()) {
1450 if (state()->isBrake()) {
1451 if (m_drivingDirection == DrivingDirection::Forwards) {
1452 m_drivingDirection = m_processedSpeed > 5.0f ? DrivingDirection::Braking :
1453 DrivingDirection::Backwards;
1454 }
1455 } else {
1456 if (m_processedSpeed >= 0.0f) {
1457 m_drivingDirection = DrivingDirection::Forwards;
1458 }
1459 }
1460 } else {
1461 m_drivingDirection = DrivingDirection::Forwards;
1462 }
1463}
1464
1469 if (!state()->isWallCollision() && !state()->isWall3Collision()) {
1470 return 1.0f;
1471 }
1472
1473 onWallCollision();
1474
1475 if (state()->isZipperInvisibleWall() || state()->isOverZipper()) {
1476 return 1.0f;
1477 }
1478
1479 EGG::Vector3f wallNrm = collisionData().wallNrm;
1480 if (wallNrm.y > 0.0f) {
1481 wallNrm.y = 0.0f;
1482 wallNrm.normalise();
1483 }
1484
1485 f32 dot = m_lastDir.dot(wallNrm);
1486
1487 if (dot < 0.0f) {
1488 f1 = std::max(0.0f, dot + 1.0f);
1489
1490 return std::min(1.0f, f1 * (state()->isWallCollision() ? 0.4f : 0.7f));
1491 }
1492
1493 return 1.0f;
1494}
1495
1501
1502 if (!state()->isWallCollisionStart()) {
1503 return;
1504 }
1505
1506 m_outsideDriftAngle = 0.0f;
1507 if (!state()->isInAction()) {
1508 m_dir = bodyFront();
1509 m_vel1Dir = m_dir;
1510 m_landingDir = m_dir;
1511 }
1512
1513 if (!state()->isZipperInvisibleWall() && !state()->isOverZipper() && param_2 < 0.9f) {
1514 f32 speedDiff = m_lastSpeed - m_speed;
1515 const CollisionData &colData = collisionData();
1516
1517 if (speedDiff > 30.0f) {
1518 m_flags.setBit(eFlags::WallBounce);
1519 EGG::Vector3f newPos = colData.relPos + pos();
1520 f32 dot = -bodyUp().dot(colData.relPos) * 0.5f;
1521 EGG::Vector3f scaledUp = dot * bodyUp();
1522 newPos -= scaledUp;
1523
1524 speedDiff = std::min(60.0f, speedDiff);
1525 EGG::Vector3f scaledWallNrm = speedDiff * colData.wallNrm;
1526
1527 auto [proj, rej] = scaledWallNrm.projAndRej(m_vel1Dir);
1528 proj *= 0.3f;
1529 rej *= 0.9f;
1530
1531 if (state()->isBoost()) {
1532 proj = EGG::Vector3f::zero;
1533 rej = EGG::Vector3f::zero;
1534 }
1535
1536 if (bodyFront().dot(colData.wallNrm) > 0.0f) {
1537 proj = EGG::Vector3f::zero;
1538 }
1539 rej *= 0.9f;
1540
1541 EGG::Vector3f projRejSum = proj + rej;
1542 f32 bumpDeviation = 0.0f;
1543 if (m_flags.offBit(eFlags::DriftReset) && state()->isTouchingGround()) {
1544 bumpDeviation = param()->stats().bumpDeviationLevel;
1545 }
1546
1547 dynamics()->applyWrenchScaled(newPos, projRejSum, bumpDeviation);
1548 } else if (wallKclType() == COL_TYPE_SPECIAL_WALL && wallKclVariant() == 2) {
1549 dynamics()->addForce(colData.wallNrm * 15.0f);
1550 collide()->startFloorMomentRate();
1551 }
1552 }
1553}
1554
1559 f32 next = 0.0f;
1560 f32 scalar = 1.0f;
1561
1562 if (state()->isTouchingGround()) {
1563 if (System::RaceManager::Instance()->stage() == System::RaceManager::Stage::Countdown) {
1564 next = 0.015f * -state()->startBoostCharge();
1565 } else if (!state()->isChargingSsmt()) {
1566 if (!state()->isJumpPad() && !state()->isRampBoost() && !state()->isSoftWallDrift()) {
1567 f32 speedDiff = m_lastSpeed - m_speed;
1568 scalar = std::min(3.0f, std::max(speedDiff, -3.0f));
1569
1570 if (state()->isMushroomBoost()) {
1571 next = (scalar * 0.15f) * 0.25f;
1572 if (state()->isWheelie()) {
1573 next *= 0.5f;
1574 }
1575 } else {
1576 next = (scalar * 0.15f) * 0.08f;
1577 }
1578 scalar = m_driftingParams->boostRotFactor;
1579 }
1580 } else {
1581 constexpr s16 MAX_SSMT_CHARGE = 75;
1582 next = 0.015f * (-static_cast<f32>(m_ssmtCharge) / static_cast<f32>(MAX_SSMT_CHARGE));
1583 }
1584 }
1585
1586 if (m_flags.onBit(eFlags::WallBounce)) {
1587 m_standStillBoostRot = isBike() ? next * 3.0f : next * 10.0f;
1588 } else {
1589 m_standStillBoostRot += scalar * (next - m_standStillBoostRot);
1590 }
1591}
1592
1597 constexpr f32 DIVE_LIMIT = 0.8f;
1598
1599 m_divingRot *= 0.96f;
1600
1601 if (state()->isTouchingGround() || state()->isCannonStart() || state()->isInCannon() ||
1602 state()->isInAction() || state()->isOverZipper()) {
1603 return;
1604 }
1605
1606 f32 stickY = state()->stickY();
1607
1608 if (state()->isInATrick() && m_jump->type() == TrickType::BikeSideStuntTrick) {
1609 stickY = std::min(1.0f, stickY + 0.4f);
1610 }
1611
1612 u32 airtime = state()->airtime();
1613
1614 if (airtime > 50) {
1615 if (EGG::Mathf::abs(stickY) < 0.1f) {
1616 m_divingRot += 0.05f * (-0.025f - m_divingRot);
1617 }
1618 } else {
1619 stickY *= (airtime / 50.0f);
1620 }
1621
1622 m_divingRot = std::max(-DIVE_LIMIT, std::min(DIVE_LIMIT, m_divingRot + stickY * 0.005f));
1623
1624 EGG::Vector3f angVel2 = dynamics()->angVel2();
1625 angVel2.x += m_divingRot;
1626 dynamics()->setAngVel2(angVel2);
1627
1628 if (state()->airtime() < 50) {
1629 return;
1630 }
1631
1632 EGG::Vector3f topRotated = dynamics()->mainRot().rotateVector(EGG::Vector3f::ey);
1633 EGG::Vector3f forwardRotated = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1634 f32 upDotTop = m_up.dot(topRotated);
1635 EGG::Vector3f upCrossTop = m_up.cross(topRotated);
1636 f32 crossNorm = upCrossTop.length();
1637 f32 angle = EGG::Mathf::abs(EGG::Mathf::atan2(crossNorm, upDotTop));
1638
1639 f32 fVar1 = angle * RAD2DEG - 20.0f;
1640 if (fVar1 <= 0.0f) {
1641 return;
1642 }
1643
1644 f32 mult = std::min(1.0f, fVar1 / 20.0f);
1645 if (forwardRotated.y > 0.0f) {
1646 dynamics()->setGravity((1.0f - 0.2f * mult) * dynamics()->gravity());
1647 } else {
1648 dynamics()->setGravity((0.2f * mult + 1.0f) * dynamics()->gravity());
1649 }
1650}
1651
1656 if (EGG::Mathf::abs(m_speed) >= 10.0f || state()->isBoost() || state()->isRampBoost() ||
1657 !state()->isAccelerate() || !state()->isBrake()) {
1658 state()->setChargingSsmt(false);
1659 return;
1660 }
1661
1662 state()->setChargingSsmt(true);
1663 state()->setHopStart(false);
1664 state()->setDriftInput(false);
1665}
1666
1668void KartMove::calcHopPhysics() {
1669 m_hopVelY = m_hopVelY * 0.998f + m_hopGravity;
1671
1672 if (m_hopPosY < 0.0f) {
1673 m_hopPosY = 0.0f;
1674 m_hopVelY = 0.0f;
1675 }
1676}
1677
1679void KartMove::calcRejectRoad() {
1680 m_reject.calcRejectRoad();
1681}
1682
1684bool KartMove::calcZipperCollision(f32 radius, f32 scale, EGG::Vector3f &pos,
1685 EGG::Vector3f &upLocal, const EGG::Vector3f &prevPos, Field::CollisionInfo *colInfo,
1686 Field::KCLTypeMask *maskOut, Field::KCLTypeMask flags) const {
1687 upLocal = mainRot().rotateVector(EGG::Vector3f::ey);
1688 pos = dynamics()->pos() + (-scale * m_scale.y) * upLocal;
1689
1690 auto *colDir = Field::CollisionDirector::Instance();
1691 return colDir->checkSphereFullPush(radius, pos, prevPos, flags, colInfo, maskOut, 0);
1692}
1693
1695f32 KartMove::calcSlerpRate(f32 scale, const EGG::Quatf &from, const EGG::Quatf &to) const {
1696 f32 dotNorm = std::max(-1.0f, std::min(1.0f, from.dot(to)));
1697 f32 acos = EGG::Mathf::acos(dotNorm);
1698 return acos > 0.0f ? std::min(0.1f, scale / acos) : 0.1f;
1699}
1700
1704 f32 tiltMagnitude = 0.0f;
1705
1706 if (!state()->isInAction() && !state()->isSoftWallDrift() && state()->isAnyWheelCollision()) {
1707 EGG::Vector3f front = componentZAxis();
1708 front = front.perpInPlane(m_up, true);
1709 EGG::Vector3f frontSpeed = velocity().rej(front).perpInPlane(m_up, false);
1710 f32 magnitude = tiltMagnitude;
1711
1712 if (frontSpeed.squaredLength() > std::numeric_limits<f32>::epsilon()) {
1713 magnitude = frontSpeed.length();
1714
1715 if (front.z * frontSpeed.x - front.x * frontSpeed.z > 0.0f) {
1716 magnitude = -magnitude;
1717 }
1718
1719 tiltMagnitude = -1.0f;
1720 if (-1.0f <= magnitude) {
1721 tiltMagnitude = std::min(1.0f, magnitude);
1722 }
1723 }
1724 } else if (!state()->isHop() || m_hopPosY <= 0.0f) {
1725 EGG::Vector3f angVel0 = dynamics()->angVel0();
1726 angVel0.z *= 0.98f;
1727 dynamics()->setAngVel0(angVel0);
1728 }
1729
1730 f32 lean = EGG::Mathf::abs(m_weightedTurn) * (tiltMagnitude * param()->stats().tilt);
1731
1733
1734 EGG::Vector3f angVel0 = dynamics()->angVel0();
1735 angVel0.x += m_standStillBoostRot;
1736 angVel0.z += lean;
1737 dynamics()->setAngVel0(angVel0);
1738
1739 EGG::Vector3f angVel2 = dynamics()->angVel2();
1740 angVel2.y += turn;
1741 dynamics()->setAngVel2(angVel2);
1742
1743 calcDive();
1744}
1745
1750 // TODO: Some of these are shared between the base and derived class implementations.
1751 constexpr u16 MAX_MT_CHARGE = 270;
1752 constexpr u16 MAX_SMT_CHARGE = 300;
1753 constexpr u16 BASE_MT_CHARGE = 2;
1754 constexpr u16 BASE_SMT_CHARGE = 2;
1755 constexpr f32 BONUS_CHARGE_STICK_THRESHOLD = 0.4f;
1756 constexpr u16 EXTRA_MT_CHARGE = 3;
1757
1758 if (m_driftState == DriftState::ChargedSmt) {
1759 return;
1760 }
1761
1762 f32 stickX = state()->stickX();
1763
1764 if (m_driftState == DriftState::ChargingMt) {
1765 m_mtCharge += BASE_MT_CHARGE;
1766
1767 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
1768 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
1769 m_mtCharge += EXTRA_MT_CHARGE;
1770 }
1771 } else if (m_hopStickX != -1) {
1772 m_mtCharge += EXTRA_MT_CHARGE;
1773 }
1774
1775 if (m_mtCharge > MAX_MT_CHARGE) {
1776 m_mtCharge = MAX_MT_CHARGE;
1777 m_driftState = DriftState::ChargingSmt;
1778 }
1779 }
1780
1781 if (m_driftState != DriftState::ChargingSmt) {
1782 return;
1783 }
1784
1785 m_smtCharge += BASE_SMT_CHARGE;
1786
1787 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
1788 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
1789 m_smtCharge += EXTRA_MT_CHARGE;
1790 }
1791 } else if (m_hopStickX != -1) {
1792 m_smtCharge += EXTRA_MT_CHARGE;
1793 }
1794
1795 if (m_smtCharge > MAX_SMT_CHARGE) {
1796 m_smtCharge = MAX_SMT_CHARGE;
1797 m_driftState = DriftState::ChargedSmt;
1798 }
1799}
1800
1802void KartMove::initOob() {
1803 clearBoost();
1804 clearJumpPad();
1805 clearRampBoost();
1806 clearZipperBoost();
1807 clearSsmt();
1808 clearOffroadInvincibility();
1809}
1810
1815 state()->setHop(true);
1816 state()->setDriftManual(false);
1817 onHop();
1818
1819 m_hopUp = dynamics()->mainRot().rotateVector(EGG::Vector3f::ey);
1820 m_hopDir = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1821 m_driftState = DriftState::NotDrifting;
1822 m_smtCharge = 0;
1823 m_mtCharge = 0;
1824 m_hopStickX = 0;
1825 m_hopFrame = 0;
1826 m_hopPosY = 0.0f;
1827 m_hopGravity = dynamics()->gravity();
1828 m_hopVelY = m_driftingParams->hopVelY;
1829 m_outsideDriftBonus = 0.0f;
1830
1831 EGG::Vector3f extVel = dynamics()->extVel();
1832 extVel.y = 0.0f + m_hopVelY;
1833 dynamics()->setExtVel(extVel);
1834
1835 EGG::Vector3f totalForce = dynamics()->totalForce();
1836 totalForce.y = 0.0f;
1837 dynamics()->setTotalForce(totalForce);
1838}
1839
1841void KartMove::tryStartBoostPanel() {
1842 constexpr s16 BOOST_PANEL_DURATION = 60;
1843
1844 if (state()->isBeforeRespawn() || state()->isInAction()) {
1845 return;
1846 }
1847
1848 activateBoost(KartBoost::Type::MushroomAndBoostPanel, BOOST_PANEL_DURATION);
1849 setOffroadInvincibility(BOOST_PANEL_DURATION);
1850}
1851
1856 constexpr s16 BOOST_RAMP_DURATION = 60;
1857
1858 if (state()->isBeforeRespawn() || state()->isInAction()) {
1859 return;
1860 }
1861
1862 state()->setRampBoost(true);
1863 m_rampBoost = BOOST_RAMP_DURATION;
1864 setOffroadInvincibility(BOOST_RAMP_DURATION);
1865}
1866
1872 static constexpr std::array<JumpPadProperties, 8> JUMP_PAD_PROPERTIES = {{
1873 {50.0f, 50.0f, 35.0f},
1874 {50.0f, 50.0f, 47.0f},
1875 {59.0f, 59.0f, 30.0f},
1876 {73.0f, 73.0f, 45.0f},
1877 {73.0f, 73.0f, 53.0f},
1878 {55.0f, 55.0f, 35.0f},
1879 {56.0f, 56.0f, 50.0f},
1880 }};
1881
1882 if (state()->isBeforeRespawn() || state()->isInAction() || state()->isHalfPipeRamp()) {
1883 return;
1884 }
1885
1886 state()->setJumpPad(true);
1887 s32 jumpPadVariant = state()->jumpPadVariant();
1888 m_jumpPadProperties = &JUMP_PAD_PROPERTIES[jumpPadVariant];
1889
1890 if (jumpPadVariant == 3 || jumpPadVariant == 4) {
1891 if (m_jumpPadBoostMultiplier > 1.3f || m_jumpPadSoftSpeedLimit > 110.0f) {
1892 // Set speed to 100 if the player has boost from a boost panel or mushroom(item) before
1893 // hitting the jump pad
1894 static constexpr std::array<JumpPadProperties, 2> JUMP_PAD_PROPERTIES_SHROOM_BOOST = {{
1895 {100.0f, 100.0f, 70.0f},
1896 {100.0f, 100.0f, 65.0f},
1897 }};
1898 m_jumpPadProperties = &JUMP_PAD_PROPERTIES_SHROOM_BOOST[jumpPadVariant != 3];
1899 }
1900 state()->setJumpPadFixedSpeed(true);
1901 }
1902
1903 if (jumpPadVariant == 4) {
1904 state()->setJumpPadMushroomTrigger(true);
1905 state()->setJumpPadMushroomVelYInc(true);
1906 state()->setJumpPadMushroomCollision(true);
1907 } else {
1908 EGG::Vector3f extVel = dynamics()->extVel();
1909 EGG::Vector3f totalForce = dynamics()->totalForce();
1910
1911 extVel.y = m_jumpPadProperties->velY;
1912 totalForce.y = 0.0f;
1913
1914 dynamics()->setExtVel(extVel);
1915 dynamics()->setTotalForce(totalForce);
1916
1917 if (jumpPadVariant != 3) {
1918 EGG::Vector3f dir = m_dir;
1919 dir.y = 0.0f;
1920 dir.normalise();
1921 m_speed *= m_dir.dot(dir);
1922 m_dir = dir;
1923 m_vel1Dir = dir;
1924 state()->setJumpPadDisableYsusForce(true);
1925 }
1926 }
1927
1928 m_jumpPadMinSpeed = m_jumpPadProperties->minSpeed;
1929 m_jumpPadMaxSpeed = m_jumpPadProperties->maxSpeed;
1930 m_speed = std::max(m_speed, m_jumpPadMinSpeed);
1931}
1932
1934void KartMove::tryEndJumpPad() {
1935 if (state()->isJumpPadMushroomTrigger()) {
1936 if (state()->isGroundStart()) {
1937 state()->setJumpPadMushroomTrigger(false);
1938 state()->setJumpPadFixedSpeed(false);
1939 state()->setJumpPadMushroomVelYInc(false);
1940 }
1941
1942 if (state()->isJumpPadMushroomVelYInc()) {
1943 EGG::Vector3f newExtVel = dynamics()->extVel();
1944 newExtVel.y += 20.0f;
1945 if (m_jumpPadProperties->velY < newExtVel.y) {
1946 newExtVel.y = m_jumpPadProperties->velY;
1947 state()->setJumpPadMushroomVelYInc(false);
1948 }
1949 dynamics()->setExtVel(newExtVel);
1950 }
1951 }
1952
1953 if (state()->isGroundStart() && !state()->isJumpPadMushroomTrigger()) {
1954 cancelJumpPad();
1955 }
1956}
1957
1959void KartMove::cancelJumpPad() {
1960 m_jumpPadMinSpeed = 0.0f;
1961 state()->setJumpPad(false);
1962}
1963
1965void KartMove::activateBoost(KartBoost::Type type, s16 frames) {
1966 if (m_boost.activate(type, frames)) {
1967 state()->setBoost(true);
1968 }
1969}
1970
1972void KartMove::applyStartBoost(s16 frames) {
1973 activateBoost(KartBoost::Type::AllMt, frames);
1974}
1975
1977void KartMove::activateMushroom() {
1978 constexpr s16 MUSHROOM_DURATION = 90;
1979
1980 if (state()->isBeforeRespawn() || state()->isInAction()) {
1981 return;
1982 }
1983
1984 activateBoost(KartBoost::Type::MushroomAndBoostPanel, MUSHROOM_DURATION);
1985
1986 m_mushroomBoostTimer = MUSHROOM_DURATION;
1987 state()->setMushroomBoost(true);
1988 setOffroadInvincibility(MUSHROOM_DURATION);
1989}
1990
1992void KartMove::activateZipperBoost() {
1993 constexpr s16 BASE_DURATION = 50;
1994 constexpr s16 TRICK_DURATION = 100;
1995
1996 if (state()->isBeforeRespawn() || state()->isInAction()) {
1997 return;
1998 }
1999
2000 s16 boostDuration = state()->isZipperTrick() ? TRICK_DURATION : BASE_DURATION;
2001 activateBoost(KartBoost::Type::TrickAndZipper, boostDuration);
2002
2003 setOffroadInvincibility(boostDuration);
2004 m_zipperBoostTimer = 0;
2005 m_zipperBoostMax = boostDuration;
2006 state()->setZipperBoost(true);
2007}
2008
2014 if (timer > m_offroadInvincibility) {
2015 m_offroadInvincibility = timer;
2016 }
2017
2018 state()->setBoostOffroadInvincibility(true);
2019}
2020
2025 if (!state()->isBoostOffroadInvincibility()) {
2026 return;
2027 }
2028
2029 if (--m_offroadInvincibility > 0) {
2030 return;
2031 }
2032
2033 state()->setBoostOffroadInvincibility(false);
2034}
2035
2039 if (!state()->isMushroomBoost()) {
2040 return;
2041 }
2042
2043 if (--m_mushroomBoostTimer > 0) {
2044 return;
2045 }
2046
2047 state()->setMushroomBoost(false);
2048}
2049
2051void KartMove::calcZipperBoost() {
2052 if (!state()->isZipperBoost()) {
2053 return;
2054 }
2055
2056 state()->setAccelerate(true);
2057
2058 if (!state()->isOverZipper() && ++m_zipperBoostTimer >= m_zipperBoostMax) {
2059 m_zipperBoostTimer = 0;
2060 state()->setZipperBoost(false);
2061 }
2062
2063 if (m_zipperBoostTimer < 10) {
2064 EGG::Vector3f angVel = dynamics()->angVel0();
2065 angVel.y = 0.0f;
2066 dynamics()->setAngVel0(angVel);
2067 }
2068}
2069
2071void KartMove::landTrick() {
2072 static constexpr std::array<s16, 3> KART_TRICK_BOOST_DURATION = {{
2073 40,
2074 70,
2075 85,
2076 }};
2077 static constexpr std::array<s16, 3> BIKE_TRICK_BOOST_DURATION = {{
2078 45,
2079 80,
2080 95,
2081 }};
2082
2083 if (state()->isBeforeRespawn() || state()->isInAction()) {
2084 return;
2085 }
2086
2087 s16 duration;
2088 if (isBike()) {
2089 duration = BIKE_TRICK_BOOST_DURATION[static_cast<u32>(m_jump->variant())];
2090 } else {
2091 duration = KART_TRICK_BOOST_DURATION[static_cast<u32>(m_jump->variant())];
2092 }
2093
2094 activateBoost(KartBoost::Type::TrickAndZipper, duration);
2095}
2096
2098void KartMove::activateCrush(u16 timer) {
2099 state()->setCrushed(true);
2100 m_crushTimer = timer;
2101 m_kartScale->startCrush();
2102}
2103
2105void KartMove::calcCrushed() {
2106 if (!state()->isCrushed()) {
2107 return;
2108 }
2109
2110 if (--m_crushTimer == 0) {
2111 state()->setCrushed(false);
2112 m_kartScale->startUncrush();
2113 }
2114}
2115
2117void KartMove::calcScale() {
2118 m_kartScale->calc();
2119 setScale(m_kartScale->currScale());
2120}
2121
2123void KartMove::enterCannon() {
2124 init(true, true);
2125 physics()->clearDecayingRot();
2126 m_boost.resetActive();
2127 state()->setBoost(false);
2128
2129 cancelJumpPad();
2130 clearRampBoost();
2131 clearZipperBoost();
2132 clearSsmt();
2133 clearOffroadInvincibility();
2134
2135 dynamics()->reset();
2136
2137 clearDrift();
2138 state()->setHop(false);
2139 state()->setInCannon(true);
2140 state()->setSkipWheelCalc(true);
2141 state()->setCannonStart(false);
2142
2143 const auto [cannonPos, cannonDir] = getCannonPosRot();
2144 m_cannonEntryPos = pos();
2145 m_cannonEntryOfs = cannonPos - pos();
2146 m_cannonEntryOfsLength = m_cannonEntryOfs.normalise();
2147 m_cannonEntryOfs.normalise();
2148 m_dir = m_cannonEntryOfs;
2149 m_vel1Dir = m_cannonEntryOfs;
2150 m_cannonOrthog = EGG::Vector3f::ey.perpInPlane(m_cannonEntryOfs, true);
2151 m_cannonProgress.setZero();
2152}
2153
2155void KartMove::calcCannon() {
2156 auto [cannonPos, cannonDir] = getCannonPosRot();
2157 EGG::Vector3f forwardXZ = cannonPos - m_cannonEntryPos - m_cannonProgress;
2158 EGG::Vector3f forward = forwardXZ;
2159 f32 forwardLength = forward.normalise();
2160 forwardXZ.y = 0;
2161 forwardXZ.normalise();
2162 EGG::Vector3f local94 = m_cannonEntryOfs;
2163 local94.y = 0;
2164 local94.normalise();
2165 m_speedRatioCapped = 1.0f;
2166 m_speedRatio = 1.5f;
2167 EGG::Matrix34f cannonOrientation;
2168 cannonOrientation.makeOrthonormalBasis(forward, EGG::Vector3f::ey);
2169 EGG::Vector3f up = cannonOrientation.multVector33(EGG::Vector3f::ey);
2170 m_smoothedUp = up;
2171 m_up = up;
2172
2173 if (forwardLength < 30.0f || local94.dot(forwardXZ) <= 0.0f) {
2174 exitCannon();
2175 return;
2176 }
2178 const auto *cannonPoint =
2179 System::CourseMap::Instance()->getCannonPoint(state()->cannonPointId());
2180 size_t cannonParameterIdx = std::max<s16>(0, cannonPoint->parameterIdx());
2181 ASSERT(cannonParameterIdx < CANNON_PARAMETERS.size());
2182 const auto &cannonParams = CANNON_PARAMETERS[cannonParameterIdx];
2183 f32 newSpeed = cannonParams.speed;
2184 if (forwardLength < cannonParams.decelFactor) {
2185 f32 factor = std::max(0.0f, forwardLength / cannonParams.decelFactor);
2186
2187 newSpeed = cannonParams.endDecel;
2188 if (newSpeed <= 0.0f) {
2189 newSpeed = m_baseSpeed;
2190 }
2191
2192 newSpeed += factor * (cannonParams.speed - newSpeed);
2193 if (cannonParams.endDecel > 0.0f) {
2194 m_speed = std::min(newSpeed, m_speed);
2195 }
2196 }
2197
2198 m_cannonProgress += m_cannonEntryOfs * newSpeed;
2199
2200 EGG::Vector3f newPos = EGG::Vector3f::zero;
2201 if (cannonParams.height > 0.0f) {
2202 f32 fVar9 = EGG::Mathf::SinFIdx(
2203 (1.0f - (forwardLength / m_cannonEntryOfsLength)) * 180.0f * DEG2FIDX);
2204 newPos = fVar9 * cannonParams.height * m_cannonOrthog;
2205 }
2206
2207 dynamics()->setPos(m_cannonEntryPos + m_cannonProgress + newPos);
2208 m_dir = m_cannonEntryOfs;
2209 m_vel1Dir = m_cannonEntryOfs;
2210
2211 calcRotCannon(forward);
2212
2213 dynamics()->setExtVel(EGG::Vector3f::zero);
2214}
2215
2217void KartMove::calcRotCannon(const EGG::Vector3f &forward) {
2218 EGG::Vector3f local48 = forward;
2219 local48.normalise();
2220 EGG::Vector3f local54 = bodyFront();
2221 EGG::Vector3f local60 = local54 + ((local48 - local54) * 0.3f);
2222 local54.normalise();
2223 local60.normalise();
2224 // also local70, localA8
2225 EGG::Quatf local80;
2226 local80.makeVectorRotation(local54, local60);
2227 local80 *= dynamics()->fullRot();
2228 local80.normalise();
2229 EGG::Quatf localB8;
2230 localB8.makeVectorRotation(local80.rotateVector(EGG::Vector3f::ey), smoothedUp());
2231 EGG::Quatf newRot = local80.slerpTo(localB8.multSwap(local80), 0.3f);
2232 dynamics()->setFullRot(newRot);
2233 dynamics()->setMainRot(newRot);
2234}
2235
2237void KartMove::exitCannon() {
2238 if (!state()->isInCannon()) {
2239 return;
2240 }
2241
2242 state()->setInCannon(false);
2243 state()->setSkipWheelCalc(false);
2244 state()->setAfterCannon(true);
2245 dynamics()->setIntVel(m_cannonEntryOfs * m_speed);
2246}
2247
2249void KartMove::triggerRespawn() {
2250 m_timeInRespawn = 0;
2251 state()->setTriggerRespawn(true);
2252}
2253
2255KartMoveBike::KartMoveBike() : m_leanRot(0.0f) {}
2256
2258KartMoveBike::~KartMoveBike() = default;
2259
2263 constexpr f32 MAX_WHEELIE_ROTATION = 0.07f;
2264 constexpr u16 WHEELIE_COOLDOWN = 20;
2265
2266 state()->setWheelie(true);
2267 m_wheelieFrames = 0;
2268 m_maxWheelieRot = MAX_WHEELIE_ROTATION;
2269 m_wheelieCooldown = WHEELIE_COOLDOWN;
2270 m_wheelieRotDec = 0.0f;
2271 m_autoHardStickXFrames = 0;
2272}
2273
2278 state()->setWheelie(false);
2279 m_wheelieRotDec = 0.0f;
2280 m_autoHardStickXFrames = 0;
2281}
2282
2284void KartMoveBike::createSubsystems() {
2285 m_jump = new KartJumpBike(this);
2286 m_halfPipe = new KartHalfPipe();
2287 m_kartScale = new KartScale();
2288}
2289
2294 f32 leanRotInc = m_turningParams->leanRotIncRace;
2295 f32 leanRotCap = m_turningParams->leanRotCapRace;
2296 const auto *raceManager = System::RaceManager::Instance();
2297
2298 if (!state()->isChargingSsmt()) {
2299 if (!raceManager->isStageReached(System::RaceManager::Stage::Race) ||
2300 EGG::Mathf::abs(m_speed) < 5.0f) {
2301 leanRotInc = m_turningParams->leanRotIncCountdown;
2302 leanRotCap = m_turningParams->leanRotCapCountdown;
2303 }
2304 } else {
2305 leanRotInc = m_turningParams->leanRotIncSSMT;
2306 leanRotCap = m_turningParams->leanRotCapSSMT;
2307 }
2308
2309 m_leanRotCap += 0.3f * (leanRotCap - m_leanRotCap);
2310 m_leanRotInc += 0.3f * (leanRotInc - m_leanRotInc);
2311
2312 f32 stickX = state()->stickX();
2313 f32 extVelXFactor = 0.0f;
2314 f32 leanRotMin = -m_leanRotCap;
2315 f32 leanRotMax = m_leanRotCap;
2316
2317 if (state()->isBeforeRespawn() || state()->isInAction() || state()->isWheelie() ||
2318 state()->isOverZipper() || state()->isRejectRoadTrigger() ||
2319 state()->isAirtimeOver20() || state()->isSoftWallDrift() ||
2320 state()->isSomethingWallCollision() || state()->isHWG() || state()->isCannonStart() ||
2321 state()->isInCannon()) {
2322 m_leanRot *= m_turningParams->leanRotDecayFactor;
2323 } else if (!state()->isDrifting()) {
2324 if (stickX <= 0.2f) {
2325 if (stickX >= -0.2f) {
2326 m_leanRot *= m_turningParams->leanRotDecayFactor;
2327 } else {
2329 extVelXFactor = m_turningParams->leanRotShallowFactor;
2330 }
2331 } else {
2333 extVelXFactor = -m_turningParams->leanRotShallowFactor;
2334 }
2335 } else {
2336 leanRotMax = m_turningParams->leanRotMaxDrift;
2337 leanRotMin = m_turningParams->leanRotMinDrift;
2338
2339 if (m_hopStickX == 1) {
2340 leanRotMin = -leanRotMax;
2341 leanRotMax = -m_turningParams->leanRotMinDrift;
2342 }
2343 if (m_hopStickX == -1) {
2344 if (stickX == 0.0f) {
2345 m_leanRot += (0.5f - m_leanRot) * 0.05f;
2346 } else {
2347 m_leanRot += m_turningParams->driftStickXFactor * stickX;
2348 extVelXFactor = -m_turningParams->leanRotShallowFactor * stickX;
2349 }
2350 } else if (stickX == 0.0f) {
2351 m_leanRot += (-0.5f - m_leanRot) * 0.05f;
2352 } else {
2353 m_leanRot += m_turningParams->driftStickXFactor * stickX;
2354 extVelXFactor = -m_turningParams->leanRotShallowFactor * stickX;
2355 }
2356 }
2357
2358 bool capped = false;
2359 if (leanRotMin <= m_leanRot) {
2360 if (leanRotMax < m_leanRot) {
2361 m_leanRot = leanRotMax;
2362 capped = true;
2363 }
2364 } else {
2365 m_leanRot = leanRotMin;
2366 capped = true;
2367 }
2368
2369 if (!capped) {
2370 dynamics()->setExtVel(dynamics()->extVel() + componentXAxis() * extVelXFactor);
2371 }
2372
2373 f32 leanRotScalar = state()->isDrifting() ? 0.065f : 0.05f;
2374
2376
2377 dynamics()->setAngVel2(dynamics()->angVel2() +
2378 EGG::Vector3f(m_standStillBoostRot, turn * wheelieRotFactor(),
2379 m_leanRot * leanRotScalar));
2380
2381 calcDive();
2382
2383 EGG::Vector3f top = m_up;
2384
2385 if (!state()->isRejectRoad() && !state()->isHalfPipeRamp() && !state()->isOverZipper()) {
2386 f32 scalar = (m_speed >= 0.0f) ? m_speedRatioCapped * 2.0f : 0.0f;
2387 scalar = std::min(1.0f, scalar);
2388 top = scalar * m_up + (1.0f - scalar) * EGG::Vector3f::ey;
2389
2390 if (std::numeric_limits<f32>::epsilon() < top.squaredLength()) {
2391 top.normalise();
2392 }
2393 }
2394
2395 dynamics()->setTop_(top);
2396}
2397
2403 static constexpr std::array<TurningParameters, 2> TURNING_PARAMS_ARRAY = {{
2404 {0.8f, 0.08f, 1.0f, 0.1f, 1.2f, 0.8f, 0.08f, 0.6f, 0.15f, 1.6f, 0.9f, 180},
2405 {1.0f, 0.1f, 1.0f, 0.05f, 1.5f, 0.7f, 0.08f, 0.6f, 0.15f, 1.3f, 0.9f, 180},
2406 }};
2407
2408 KartMove::setTurnParams();
2409
2410 if (param()->stats().driftType == KartParam::Stats::DriftType::Outside_Drift_Bike) {
2411 m_turningParams = &TURNING_PARAMS_ARRAY[0];
2412 } else if (param()->stats().driftType == KartParam::Stats::DriftType::Inside_Drift_Bike) {
2413 m_turningParams = &TURNING_PARAMS_ARRAY[1];
2414 }
2415
2416 if (System::RaceManager::Instance()->isStageReached(System::RaceManager::Stage::Race)) {
2417 m_leanRotInc = m_turningParams->leanRotIncRace;
2418 m_leanRotCap = m_turningParams->leanRotCapRace;
2419 } else {
2420 m_leanRotInc = m_turningParams->leanRotIncCountdown;
2421 m_leanRotCap = m_turningParams->leanRotCapCountdown;
2422 }
2423}
2424
2426void KartMoveBike::init(bool b1, bool b2) {
2427 KartMove::init(b1, b2);
2428
2429 m_leanRot = 0.0f;
2430 m_leanRotCap = 0.0f;
2431 m_leanRotInc = 0.0f;
2432 m_wheelieRot = 0.0f;
2433 m_maxWheelieRot = 0.0f;
2434 m_wheelieFrames = 0;
2436 m_autoHardStickXFrames = 0;
2437}
2438
2440void KartMoveBike::clear() {
2441 KartMove::clear();
2442 cancelWheelie();
2443}
2444
2448 constexpr u32 FAILED_WHEELIE_FRAMES = 15;
2449 constexpr f32 AUTO_WHEELIE_CANCEL_STICK_THRESHOLD = 0.85f;
2450
2452 m_wheelieCooldown = std::max(0, m_wheelieCooldown - 1);
2453
2454 if (state()->isWheelie()) {
2455 bool cancelAutoWheelie = false;
2456
2457 if (!state()->isAutoDrift() ||
2458 EGG::Mathf::abs(state()->stickX()) <= AUTO_WHEELIE_CANCEL_STICK_THRESHOLD) {
2459 m_autoHardStickXFrames = 0;
2460 } else {
2461 if (++m_autoHardStickXFrames > 15) {
2462 cancelAutoWheelie = true;
2463 }
2464 }
2465
2467 if (m_turningParams->maxWheelieFrames < m_wheelieFrames || cancelAutoWheelie ||
2468 (!canWheelie() && FAILED_WHEELIE_FRAMES <= m_wheelieFrames)) {
2469 cancelWheelie();
2470 } else {
2471 m_wheelieRot += 0.01f;
2472 EGG::Vector3f angVel0 = dynamics()->angVel0();
2473 angVel0.x *= 0.9f;
2474 dynamics()->setAngVel0(angVel0);
2475 }
2476 } else if (0.0f < m_wheelieRot) {
2477 m_wheelieRotDec -= 0.001f;
2478 m_wheelieRotDec = std::max(-0.03f, m_wheelieRotDec);
2480 }
2481
2482 m_wheelieRot = std::max(0.0f, std::min(m_wheelieRot, m_maxWheelieRot));
2483
2484 f32 vel1DirUp = m_vel1Dir.dot(EGG::Vector3f::ey);
2485
2486 if (m_wheelieRot > 0.0f) {
2487 if (vel1DirUp <= 0.5f || m_wheelieFrames < FAILED_WHEELIE_FRAMES) {
2488 EGG::Vector3f angVel2 = dynamics()->angVel2();
2489 angVel2.x -= m_wheelieRot * (1.0f - EGG::Mathf::abs(vel1DirUp));
2490 dynamics()->setAngVel2(angVel2);
2491 } else {
2492 cancelWheelie();
2493 }
2494
2495 state()->setWheelieRot(true);
2496 } else {
2497 state()->setWheelieRot(false);
2498 }
2499}
2500
2507 if (state()->isAutoDrift()) {
2508 return;
2509 }
2510
2511 cancelWheelie();
2512}
2513
2519
2524 constexpr u16 MAX_MT_CHARGE = 270;
2525 constexpr u16 BASE_MT_CHARGE = 2;
2526 constexpr f32 BONUS_CHARGE_STICK_THRESHOLD = 0.4f;
2527 constexpr u16 EXTRA_MT_CHARGE = 3;
2528
2529 if (m_driftState != DriftState::ChargingMt) {
2530 return;
2531 }
2532
2533 m_mtCharge += BASE_MT_CHARGE;
2534
2535 f32 stickX = state()->stickX();
2536 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
2537 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
2538 m_mtCharge += EXTRA_MT_CHARGE;
2539 }
2540 } else if (m_hopStickX != -1) {
2541 m_mtCharge += EXTRA_MT_CHARGE;
2542 }
2543
2544 if (m_mtCharge > MAX_MT_CHARGE) {
2545 m_mtCharge = MAX_MT_CHARGE;
2546 m_driftState = DriftState::ChargedMt;
2547 }
2548}
2549
2551void KartMoveBike::initOob() {
2552 KartMove::initOob();
2553 cancelWheelie();
2554}
2555
2559 constexpr s16 COOLDOWN_FRAMES = 20;
2560 bool dpadUp = inputs()->currentState().trickUp();
2561
2562 if (!state()->isWheelie()) {
2563 if (dpadUp && state()->isTouchingGround()) {
2564 if (state()->isDriftManual() || state()->isWallCollision() ||
2565 state()->isWall3Collision() || state()->isHop() || state()->isDriftAuto() ||
2566 state()->isInAction()) {
2567 return;
2568 }
2569
2570 if (m_wheelieCooldown > 0) {
2571 return;
2572 }
2573
2574 startWheelie();
2575 }
2576 } else if (inputs()->currentState().trickDown() && m_wheelieCooldown <= 0) {
2577 cancelWheelie();
2578 m_wheelieCooldown = COOLDOWN_FRAMES;
2579 }
2580}
2581
2582} // namespace Kart
@ 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_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
A 3 x 4 matrix.
Definition Matrix.hh:8
void makeOrthonormalBasis(const Vector3f &v0, const Vector3f &v1)
Sets a 3x3 orthonormal basis for a local coordinate system.
Definition Matrix.cc:154
void setAxisRotation(f32 angle, const Vector3f &axis)
Rotates the matrix about an axis.
Definition Matrix.cc:167
Vector3f multVector33(const Vector3f &vec) const
Multiplies a 3x3 matrix by a vector.
Definition Matrix.cc:236
Vector3f multVector(const Vector3f &vec) const
Multiplies a vector by a matrix.
Definition Matrix.cc:212
bool activate(Type type, s16 frames)
Starts/restarts a boost of the given type.
Definition KartBoost.cc:21
bool calc()
Computes the current frame's boost multiplier, acceleration, and speed limit.
Definition KartBoost.cc:38
void applyWrenchScaled(const EGG::Vector3f &p, const EGG::Vector3f &f, f32 scale)
Applies a force linearly and rotationally to the kart.
Handles the physics and boosts associated with zippers.
f32 m_leanRot
Z-axis rotation of the bike from leaning.
Definition KartMove.hh:509
f32 m_leanRotCap
The maximum leaning rotation.
Definition KartMove.hh:510
void calcWheelie() override
STAGE 1+ - Every frame, checks player input for wheelies and computes wheelie rotation.
Definition KartMove.cc:2447
void calcMtCharge() override
Every frame during a drift, calculates MT charge based on player input.
Definition KartMove.cc:2523
virtual void startWheelie()
STAGE 1+ - Sets the wheelie bit flag and some wheelie-related variables.
Definition KartMove.cc:2262
f32 m_wheelieRotDec
The wheelie rotation decrementor, used after a wheelie has ended.
Definition KartMove.hh:516
u32 m_wheelieFrames
Tracks wheelie duration and cancels the wheelie after 180 frames.
Definition KartMove.hh:514
f32 m_wheelieRot
X-axis rotation from wheeling.
Definition KartMove.hh:512
const TurningParameters * m_turningParams
Inside/outside drifting bike turn info.
Definition KartMove.hh:518
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:2402
f32 m_maxWheelieRot
The maximum wheelie rotation.
Definition KartMove.hh:513
void tryStartWheelie()
STAGE 1+ - Every frame, checks player input to see if we should start or stop a wheelie.
Definition KartMove.cc:2558
void onWallCollision() override
Called when you collide with a wall. All it does for bikes is cancel wheelies.
Definition KartMove.cc:2516
void onHop() override
Virtual function that just cancels wheelies when you hop.
Definition KartMove.cc:2506
bool canWheelie() const override
Checks if the kart is going fast enough to wheelie.
Definition KartMove.hh:500
void calcVehicleRotation(f32) override
Every frame, calculates rotation, EV, and angular velocity for the bike.
Definition KartMove.cc:2293
s16 m_wheelieCooldown
The number of frames before another wheelie can start.
Definition KartMove.hh:515
f32 m_leanRotInc
The incrementor for leaning rotation.
Definition KartMove.hh:511
virtual void cancelWheelie()
Clears the wheelie bit flag and resets the rotation decrement.
Definition KartMove.cc:2277
f32 m_baseSpeed
The speed associated with the current character/vehicle stats.
Definition KartMove.hh:352
void calcRotation()
Every frame, calculates kart rotation based on player input.
Definition KartMove.cc:1104
s16 m_ssmtLeewayTimer
Frames to forgive letting go of A before clearing SSMT charge.
Definition KartMove.hh:394
s32 m_hopFrame
A timer that can prevent subsequent hops until reset.
Definition KartMove.hh:379
void calcDisableBackwardsAccel()
Computes the current cooldown duration between braking and reversing.
Definition KartMove.cc:690
EGG::Vector3f m_hopUp
The up vector when hopping.
Definition KartMove.hh:380
u16 m_mushroomBoostTimer
Number of frames until the mushroom boost runs out.
Definition KartMove.hh:401
void calcSpecialFloor()
Every frame, calculates any boost resulting from a boost panel.
Definition KartMove.cc:492
void calcWallCollisionStart(f32 param_2)
If we started to collide with a wall this frame, applies rotation.
Definition KartMove.cc:1499
KartHalfPipe * m_halfPipe
Pertains to zipper physics.
Definition KartMove.hh:429
f32 m_kclRotFactor
Float between 0-1 that scales the player's turning radius on offroad.
Definition KartMove.hh:374
f32 m_outsideDriftBonus
Added to angular velocity when outside drifting.
Definition KartMove.hh:387
void tryStartBoostRamp()
Sets offroad invincibility and and enables the ramp boost bitfield flag.
Definition KartMove.cc:1855
void calcDeceleration()
Definition KartMove.cc:1279
u16 m_smtCharge
A value between 0 and 300 representing current SMT charge.
Definition KartMove.hh:386
f32 m_speedRatio
The ratio between current speed and the player's base speed stat.
Definition KartMove.hh:372
@ DriftReset
Set when a wall bonk should cancel your drift.
@ SsmtCharged
Set after holding a stand-still mini-turbo for 75 frames.
@ TrickableSurface
Set when driving on a trickable surface.
@ SsmtLeeway
If set, activates SSMT when not pressing A or B.
@ WallBounce
Set when our speed loss from wall collision is > 30.0f.
@ Respawned
Set when Lakitu lets go of the player, cleared when landing.
void tryStartJumpPad()
Applies calculations to start interacting with a jump pad.
Definition KartMove.cc:1871
f32 m_jumpPadMinSpeed
Snaps the player to a minimum speed when first touching a jump pad.
Definition KartMove.hh:404
f32 m_hopPosY
Relative position as the result of a hop. Starts at 0.
Definition KartMove.hh:418
DrivingDirection m_drivingDirection
Current state of driver's direction.
Definition KartMove.hh:424
u16 m_crushTimer
Number of frames until player will be uncrushed.
Definition KartMove.hh:402
bool calcPreDrift()
Each frame, checks for hop or slipdrift. Computes drift direction based on player input.
Definition KartMove.cc:760
f32 m_speed
Current speed, restricted to the soft speed limit.
Definition KartMove.hh:354
s16 m_offroadInvincibility
How many frames until the player is affected by offroad.
Definition KartMove.hh:392
void calcAirtimeTop()
Calculates rotation of the bike due to excessive airtime.
Definition KartMove.cc:469
void startManualDrift()
Called when the player lands from a drift hop, or to start a slipdrift.
Definition KartMove.cc:1004
void controlOutsideDriftAngle()
Every frame, handles mini-turbo charging and outside drifting bike rotation.
Definition KartMove.cc:1071
f32 m_softSpeedLimit
Base speed + boosts + wheelies, restricted to the hard speed limit.
Definition KartMove.hh:353
virtual void hop()
Initializes hop information, resets upwards EV and clears upwards force.
Definition KartMove.cc:1814
void calcStandstillBoostRot()
STAGE Computes the x-component of angular velocity based on the kart's speed.
Definition KartMove.cc:1558
EGG::Vector3f m_outsideDriftLastDir
Used to compute the next m_outsideDriftAngle.
Definition KartMove.hh:370
void calcManualDrift()
Each frame, handles hopping, drifting, and mini-turbos.
Definition KartMove.cc:928
virtual void calcMtCharge()
Every frame during a drift, calculates MT/SMT charge based on player input.
Definition KartMove.cc:1749
void calcSsmt()
Calculates standstill mini-turbo components, if applicable.
Definition KartMove.cc:705
void calcAcceleration()
Every frame, applies acceleration to the kart's internal velocity.
Definition KartMove.cc:1327
f32 m_processedSpeed
Offset 0x28. It's only ever just a copy of m_speed.
Definition KartMove.hh:356
void releaseMt()
Stops charging a mini-turbo, and applies boost if charged.
Definition KartMove.cc:1047
f32 m_kclSpeedFactor
Float between 0-1 that scales the player's speed on offroad.
Definition KartMove.hh:373
f32 m_weightedTurn
Magnitude+direction of stick input, factoring in the kart's stats.
Definition KartMove.hh:397
void calcVehicleSpeed()
Every frame, computes speed based on acceleration and any active boosts.
Definition KartMove.cc:1200
f32 m_lastSpeed
Last frame's speed, cached to calculate angular velocity.
Definition KartMove.hh:355
s16 m_ssmtDisableAccelTimer
Counter that tracks delay before starting to reverse.
Definition KartMove.hh:395
void calcOffroadInvincibility()
Checks a timer to see if we are still ignoring offroad slowdown.
Definition KartMove.cc:2024
KartBurnout m_burnout
Manages the state of start boost burnout.
Definition KartMove.hh:431
f32 calcVehicleAcceleration() const
Every frame, computes acceleration based off the character/vehicle stats.
Definition KartMove.cc:1293
void calcAutoDrift()
Each frame, handles automatic transmission drifting.
Definition KartMove.cc:876
f32 m_realTurn
The "true" turn magnitude. Equal to m_weightedTurn unless drifting.
Definition KartMove.hh:396
const DriftingParameters * m_driftingParams
Drift-type-specific parameters.
Definition KartMove.hh:432
void clearDrift()
Definition KartMove.cc:812
void calc()
Each frame, calculates the kart's movement.
Definition KartMove.cc:276
EGG::Vector3f m_up
Vector perpendicular to the floor, pointing upwards.
Definition KartMove.hh:361
s16 m_ssmtCharge
Increments every frame up to 75 when charging stand-still MT.
Definition KartMove.hh:393
f32 m_speedDragMultiplier
After 5 frames of airtime, this causes speed to slowly decay.
Definition KartMove.hh:359
u16 m_mtCharge
A value between 0 and 270 representing current MT charge.
Definition KartMove.hh:385
void calcSsmtStart()
Calculates whether we are starting a standstill mini-turbo.
Definition KartMove.cc:1655
s16 m_respawnPostLandTimer
Counts up to 4 if not accelerating after respawn landing.
Definition KartMove.hh:422
virtual f32 getWheelieSoftSpeedLimitBonus() const
Returns the % speed boost from wheelies. For karts, this is always 0.
Definition KartMove.hh:100
f32 m_kclWheelRotFactor
The slowest rotation multiplier of each wheel's floor collision.
Definition KartMove.hh:376
void resetDriftManual()
Clears drift state. Called when touching ground and drift is canceled.
Definition KartMove.cc:800
f32 m_totalScale
[Unused] Always 1.0f
Definition KartMove.hh:399
f32 m_acceleration
Captures the acceleration from player input and boosts.
Definition KartMove.hh:358
virtual void calcVehicleRotation(f32 turn)
Every frame, calculates rotation, EV, and angular velocity for the kart.
Definition KartMove.cc:1703
s16 m_respawnPreLandTimer
Counts down from 4 when pressing A before landing from respawn.
Definition KartMove.hh:421
virtual void calcTurn()
Each frame, looks at player input and kart stats. Saves turn-related info.
Definition KartMove.cc:67
f32 m_divingRot
Induces x-axis angular velocity based on up/down stick input.
Definition KartMove.hh:382
f32 m_outsideDriftAngle
The facing angle of an outward-drifting vehicle.
Definition KartMove.hh:368
EGG::Vector3f m_lastDir
m_speed from the previous frame but with signed magnitude.
Definition KartMove.hh:364
EGG::Vector3f m_smoothedUp
A smoothed up vector, mostly used after significant airtime.
Definition KartMove.hh:360
s32 getAppliedHopStickX() const
Factors in vehicle speed to retrieve our hop direction and magnitude.
Definition KartMove.hh:209
u16 m_floorCollisionCount
The number of tires colliding with the floor.
Definition KartMove.hh:377
void calcDive()
Responds to player input to handle up/down kart tilt mid-air.
Definition KartMove.cc:1596
void calcOffroad()
Each frame, computes rotation and speed scalars from the floor KCL.
Definition KartMove.cc:635
KartScale * m_kartScale
Manages scaling due to TF stompers and MH cars.
Definition KartMove.hh:430
@ WaitingForBackwards
Holding reverse but waiting on a 15 frame delay.
s16 m_timeInRespawn
The number of frames elapsed after position snap from respawn.
Definition KartMove.hh:420
s32 m_hopStickX
A ternary for the direction of our hop, 0 if still neutral hopping.
Definition KartMove.hh:378
s16 m_backwardsAllowCounter
Tracks the 15f delay before reversing.
Definition KartMove.hh:425
f32 calcWallCollisionSpeedFactor(f32 &f1)
Every frame, computes a speed scalar if we are colliding with a wall.
Definition KartMove.cc:1468
void calcMushroomBoost()
Checks a timer to see if we are still boosting from a mushroom.
Definition KartMove.cc:2038
f32 m_hopGravity
Always main gravity (-1.3f).
Definition KartMove.hh:419
f32 m_hopVelY
Relative velocity due to a hop. Starts at 10 and decreases with gravity.
Definition KartMove.hh:417
f32 m_hardSpeedLimit
Absolute speed cap. It's 120, unless you're in a bullet (140).
Definition KartMove.hh:357
void setInitialPhysicsValues(const EGG::Vector3f &position, const EGG::Vector3f &angles)
Initializes the kart's position and rotation. Calls tire suspension initializers.
Definition KartMove.cc:239
f32 m_rawTurn
Float in range [-1, 1]. Represents stick magnitude + direction.
Definition KartMove.hh:433
void setOffroadInvincibility(s16 timer)
Ignores offroad KCL collision for a set amount of time.
Definition KartMove.cc:2013
f32 m_speedRatioCapped
m_speedRatio but capped at 1.0f.
Definition KartMove.hh:371
EGG::Vector3f m_scale
Normally the unit vector, but may vary due to crush animations.
Definition KartMove.hh:398
f32 m_kclWheelSpeedFactor
The slowest speed multiplier of each wheel's floor collision.
Definition KartMove.hh:375
EGG::Vector3f m_hopDir
Used for outward drift. Tracks the forward vector of our rotation.
Definition KartMove.hh:381
EGG::Vector3f bodyUp() const
Returns the second column of the rotation matrix, which is the "up" direction.
EGG::Vector3f bodyFront() const
Returns the third column of the rotation matrix, which is the facing vector.
Mainly responsible for calculating scaling for the squish/unsquish animation.
Definition KartScale.hh:8
EGG core library.
Definition Archive.cc:6
Pertains to kart-related functionality.
@ BikeSideStuntTrick
A side StuntTrick with a bike.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
void normalise()
Scales the quaternion to a unit length.
Definition Quat.cc:28
Vector3f rotateVector(const Vector3f &vec) const
Rotates a vector based on the quat.
Definition Quat.cc:55
Quatf slerpTo(const Quatf &q2, f32 t) const
Performs spherical linear interpolation.
Definition Quat.cc:84
void setAxisRotation(f32 angle, const Vector3f &axis)
Set the quat given angle and axis.
Definition Quat.cc:111
f32 dot(const Quatf &q) const
Computes .
Definition Quat.hh:107
void makeVectorRotation(const Vector3f &from, const Vector3f &to)
Captures rotation between two vectors.
Definition Quat.cc:40
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:68
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:103
constexpr TBitFlag< T, E > & changeBit(bool on, Es... es)
Changes the state of the corresponding bits for the provided enum values.
Definition BitFlag.hh:80
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:136
constexpr void makeAllZero()
Resets all the bits to zero.
Definition BitFlag.hh:229
constexpr TBitFlag< T, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:57
A 3D float vector.
Definition Vector.hh:87
f32 normalise()
Normalizes the vector and returns the original length.
Definition Vector.cc:44
f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
Definition Vector.hh:186
f32 length() const
The square root of the vector's dot product.
Definition Vector.hh:191
f32 squaredLength() const
The dot product between the vector and itself.
Definition Vector.hh:181
Vector3f proj(const Vector3f &rhs) const
The projection of this vector onto rhs.
Definition Vector.hh:197
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.cc:96
Vector3f rej(const Vector3f &rhs) const
The rejection of this vector onto rhs.
Definition Vector.hh:203
Information about the current collision and its properties.
f32 driftManualTightness
Affects turn radius when manual drifting.
Definition KartParam.hh:106
std::array< f32, 32 > kclRot
Rotation scalars, indexed using KCL attributes.
Definition KartParam.hh:113
f32 driftAutomaticTightness
Affects turn radius when automatic drifting.
Definition KartParam.hh:107
f32 driftReactivity
A weight applied to turn radius when drifting.
Definition KartParam.hh:108
f32 speed
Base full speed of the character/vehicle combo.
Definition KartParam.hh:96
f32 handlingReactivity
A weight applied to turn radius when not drifting.
Definition KartParam.hh:105
u32 miniTurbo
The framecount duration of a charged mini-turbo.
Definition KartParam.hh:111