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