Advertisement
Faschz

DKR - Velocity 101

Apr 29th, 2020 (edited)
1,409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.35 KB | None | 0 0
  1. // IMPORTANT! Keep in mind that in DKR, forward velocity is a negative number!!!
  2.  
  3. // Also this code isn't necessarily 1:1 for floating point related things. A lot
  4. // of the constants they used were doubles. I suspect they wrote something like
  5. // "1.7 * player->throttle" instead of "1.7f * player->throttle"
  6.  
  7. // So before we look into calculating what the new velocity is, we need to take
  8. // into consideration how throttle is calculated. This is eventually used to see
  9. // how far you accelerate.
  10.  
  11. // If the player is holding A or boosting
  12. player->throttle = 1.0f;  // 800536B8
  13. // If the player is not holding A
  14. player->throttle -= 0.1f; // 80053698
  15.  
  16. // Traction is based on the surface you are on, keep in mind the kart has 4
  17. // wheels and the traction is calculated using all of them! Here are some
  18. // examples. The lower the traction the smaller the velocity penalty. These all
  19. // assume all 4 wheels are on the surface.
  20. // Sand = 0.010f
  21. // Grass = 0.007f
  22. // Road = 0.004f
  23.  
  24. // If the player is holding A
  25. player->velocity -= -1.0f * SQ(player->velocity) * traction; // 800519B4
  26. // If the player is not holding A
  27. player->velocity -= 8.0f * player->velocity * traction;      // 800519A0
  28.  
  29. // The thing to note here is that if you aren't holding A you lose less speed
  30. // when your velocity is greater than -8.0f. This can be seen by setting the
  31. // above equal to eachother...
  32. // velocity^2 * traction = 8 * velocity * traction
  33. // velocity^2 = 8 * velocity (Cut out the traction, its a constant)
  34. // velocity = 8 (Cancel out one of the velocities)
  35.  
  36. // There are some special cases where you can increase your acceleration by a
  37. // certain percentage outside of just holding A to set your throttle. For
  38. // instance you can drift to increase by 10% and bananas increase by 2.5%
  39. bonus_accel = 1.0f;
  40.  
  41. // Only if drifting
  42. bonus_accel *= 1.1f;
  43.  
  44. // The game has a cap of 10 bananas for the boost on your acceleration, however
  45. // with the use of VITAMINB this cap can be raised to 20. Another thing of note
  46. // is that BOGUSBANANAS instead of increasing by 2.5%, it decreases  by 2.5%.
  47. // The same banana cap rules apply.
  48. bonus_accel *= 1.0f + 0.025f * player->bananas;
  49.  
  50. velocity = fabs(player->velocity);
  51. idx = (u32) velocity;
  52. remainder = velocity - (f32) idx;
  53.  
  54. // The index into this table will cap at [12], thus the furthest read will be
  55. // [13]. The table has 15 entrants however, the last one is never used.. its
  56. // just a copy of the previous one anyway. Each table will be different for each
  57. // character, this is how each character gets their stats.
  58. // Here is Diddy's for example...
  59. // f32 table[] = { 0.10f, 0.12f, 0.15f, 0.17f, 0.19f, 0.21f, 0.25f, 0.28f, 0.29f, 0.30f, 0.32f, 0.34f, 0.34f, 0.34f };
  60. interpolated = (1.0f - remainder)*table[idx] + remainder*table[idx + 1];
  61.  
  62. // If you are not boosting
  63. player->velocity -= 1.7f * bonus_accel * player->throttle * interpolated;       // 80051EC0
  64. // If you are boosting
  65. player->velocity -= 2.0f;
  66.  
  67. player->velocity += 0.32f * 1.7f * bonus_accel * player->brake * interpolated;  // 80051F2C
  68.  
  69. // Here is a small section relating to slopes, pitch here is a float from
  70. // -1.0f to 1.0f. Kart nose down in the ground is -1.0f, kart nose up in the sky
  71. // is 1.0f. So you'll see that you'll gain speed when driving down slopes and
  72. // lose speed when driving up slopes. Another point is the pitch is divided by
  73. // a variable so that you gain EIGHT times as much speed going down a hill than
  74. // you would lose going up the same hill. (4.0f / 0.5f = 8.0f). Now, I should
  75. // also state that this pitch isn't for the slope under your kart, but rather
  76. // the kart itself so this change can be applied even when not on sloped
  77. // surfaces with a crooked kart.
  78.  
  79. // If kart nose down in ground.
  80. player->velocity += 2.0f * 0.45f * (pitch / 0.5f); // 800520D0
  81. // If kart nose is up in the sky.
  82. player->velocity += 2.0f * 0.45f * (pitch / 4.0f); // 800520D0
  83.  
  84. // Heres a note on how you can calculate top speed using this information!
  85. // I'm going to use Diddy for this example. The top speed is determined by
  86. // the speed you lose from traction and the acceleration from throttle.
  87. // If you set them equal you can calculate for top speed!
  88. // traction * velocity^2 = 1.7f * banana_accel * throttle * interpolated
  89. // Since we know that we're looking for top speed we can set the throttle to 1.0
  90. // We also know that we're going to be using the last 2 entrants in our table,
  91. // this gives 0.34f for the interpolated value. This leaves the following:
  92. // traction * velocity^2 = 1.7f * 0.34f * banana_accel
  93. // A couple more assumptions, lets assume we have 0 bananas, this gives us 1.0f
  94. // for banana_accel. Let's assume you are driving on the road, this gives 0.004f
  95. // for the traction. Thus:
  96. // 0.004f * velocity^2 = 1.7f * 0.34f
  97. // velocity^2 = (1.7f * 0.34f) / 0.004f
  98. // velocity^2 = 144.5
  99. // velocity = 12.02f
  100. // Now for 10 bananas.. thats velocity^2 = (1.7f * 0.34f * 1.25f) / 0.004f
  101. // So velocity = 13.44f
  102.  
  103. // Now lets say you are using a boost and not holding A. The top speed will be
  104. // even higher since the penalty from traction is lower and the velocity
  105. // increase is a constant number. Heres how to calculate this top speed using
  106. // this information. Character and banana count does not matter in this
  107. // situation.
  108. // 8.0f * velocity * 0.004f = 2.0f
  109. // velocity = 2.0f / (8.0f * 0.004f)
  110. // velocity = 2.0f / 0.032f
  111. // velocity = 62.5f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement