Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IMPORTANT! Keep in mind that in DKR, forward velocity is a negative number!!!
- // Also this code isn't necessarily 1:1 for floating point related things. A lot
- // of the constants they used were doubles. I suspect they wrote something like
- // "1.7 * player->throttle" instead of "1.7f * player->throttle"
- // So before we look into calculating what the new velocity is, we need to take
- // into consideration how throttle is calculated. This is eventually used to see
- // how far you accelerate.
- // If the player is holding A or boosting
- player->throttle = 1.0f; // 800536B8
- // If the player is not holding A
- player->throttle -= 0.1f; // 80053698
- // Traction is based on the surface you are on, keep in mind the kart has 4
- // wheels and the traction is calculated using all of them! Here are some
- // examples. The lower the traction the smaller the velocity penalty. These all
- // assume all 4 wheels are on the surface.
- // Sand = 0.010f
- // Grass = 0.007f
- // Road = 0.004f
- // If the player is holding A
- player->velocity -= -1.0f * SQ(player->velocity) * traction; // 800519B4
- // If the player is not holding A
- player->velocity -= 8.0f * player->velocity * traction; // 800519A0
- // The thing to note here is that if you aren't holding A you lose less speed
- // when your velocity is greater than -8.0f. This can be seen by setting the
- // above equal to eachother...
- // velocity^2 * traction = 8 * velocity * traction
- // velocity^2 = 8 * velocity (Cut out the traction, its a constant)
- // velocity = 8 (Cancel out one of the velocities)
- // There are some special cases where you can increase your acceleration by a
- // certain percentage outside of just holding A to set your throttle. For
- // instance you can drift to increase by 10% and bananas increase by 2.5%
- bonus_accel = 1.0f;
- // Only if drifting
- bonus_accel *= 1.1f;
- // The game has a cap of 10 bananas for the boost on your acceleration, however
- // with the use of VITAMINB this cap can be raised to 20. Another thing of note
- // is that BOGUSBANANAS instead of increasing by 2.5%, it decreases by 2.5%.
- // The same banana cap rules apply.
- bonus_accel *= 1.0f + 0.025f * player->bananas;
- velocity = fabs(player->velocity);
- idx = (u32) velocity;
- remainder = velocity - (f32) idx;
- // The index into this table will cap at [12], thus the furthest read will be
- // [13]. The table has 15 entrants however, the last one is never used.. its
- // just a copy of the previous one anyway. Each table will be different for each
- // character, this is how each character gets their stats.
- // Here is Diddy's for example...
- // 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 };
- interpolated = (1.0f - remainder)*table[idx] + remainder*table[idx + 1];
- // If you are not boosting
- player->velocity -= 1.7f * bonus_accel * player->throttle * interpolated; // 80051EC0
- // If you are boosting
- player->velocity -= 2.0f;
- player->velocity += 0.32f * 1.7f * bonus_accel * player->brake * interpolated; // 80051F2C
- // Here is a small section relating to slopes, pitch here is a float from
- // -1.0f to 1.0f. Kart nose down in the ground is -1.0f, kart nose up in the sky
- // is 1.0f. So you'll see that you'll gain speed when driving down slopes and
- // lose speed when driving up slopes. Another point is the pitch is divided by
- // a variable so that you gain EIGHT times as much speed going down a hill than
- // you would lose going up the same hill. (4.0f / 0.5f = 8.0f). Now, I should
- // also state that this pitch isn't for the slope under your kart, but rather
- // the kart itself so this change can be applied even when not on sloped
- // surfaces with a crooked kart.
- // If kart nose down in ground.
- player->velocity += 2.0f * 0.45f * (pitch / 0.5f); // 800520D0
- // If kart nose is up in the sky.
- player->velocity += 2.0f * 0.45f * (pitch / 4.0f); // 800520D0
- // Heres a note on how you can calculate top speed using this information!
- // I'm going to use Diddy for this example. The top speed is determined by
- // the speed you lose from traction and the acceleration from throttle.
- // If you set them equal you can calculate for top speed!
- // traction * velocity^2 = 1.7f * banana_accel * throttle * interpolated
- // Since we know that we're looking for top speed we can set the throttle to 1.0
- // We also know that we're going to be using the last 2 entrants in our table,
- // this gives 0.34f for the interpolated value. This leaves the following:
- // traction * velocity^2 = 1.7f * 0.34f * banana_accel
- // A couple more assumptions, lets assume we have 0 bananas, this gives us 1.0f
- // for banana_accel. Let's assume you are driving on the road, this gives 0.004f
- // for the traction. Thus:
- // 0.004f * velocity^2 = 1.7f * 0.34f
- // velocity^2 = (1.7f * 0.34f) / 0.004f
- // velocity^2 = 144.5
- // velocity = 12.02f
- // Now for 10 bananas.. thats velocity^2 = (1.7f * 0.34f * 1.25f) / 0.004f
- // So velocity = 13.44f
- // Now lets say you are using a boost and not holding A. The top speed will be
- // even higher since the penalty from traction is lower and the velocity
- // increase is a constant number. Heres how to calculate this top speed using
- // this information. Character and banana count does not matter in this
- // situation.
- // 8.0f * velocity * 0.004f = 2.0f
- // velocity = 2.0f / (8.0f * 0.004f)
- // velocity = 2.0f / 0.032f
- // velocity = 62.5f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement