Actions

SPG:Special Abilities

From Sonic Retro

Spindash (Sonic 2, 3, & K)

When you first begin the Spindash, a variable (let's call it p) is set to 0. With every press of the button, p is increased by 2, up to a maximum of 8. Furthermore, during the entire time the Spindash is charging, p is being affected by the following calculation:

p -= ((p div 0.125) / 256); //"div" is division ignoring any remainder

This is exactly like the air drag calculation.

What this means is that the higher p is, the faster it bleeds away toward zero.

When you release the Down button, the character launches forward at a speed of 8, plus floor(p) - i.e. p minus its fractional part (everything after the decimal point) - divided by 2.

xsp = 8 + (floor(p) / 2); //this would be negative if the character were facing left, of course

Because the higher p is, the faster it depletes, it is nearly impossible to get maximum thrust from a Spindash without the aid of a Turbo controller or frame-by-frame play. However, if you were able to, the highest speed achievable through the Spindash is 12.

Note: Water has no effect on the release speed.

Spindash (Sonic CD)

The Sonic CD style Spindash is much simpler. Many Sonic players may find it inferior to the Sonic 2 style, though, so you may not want to use it in your engine. Or, if you do, you might include a choice in the control options which one to use.

Once the button is pressed, Sonic will begin charging the Spindash. After 45 steps have passed, he is ready to go. When the Down button is released, Sonic launches at a speed of 12. If the Down button is released early, nothing happens.

Dash (Super Peel Out)

Once the button is pressed, Sonic will begin charging the Dash. After 30 steps have passed, he is ready to go. When the Up button is released, Sonic launches at a speed of 12. If the Up button is released early, nothing happens.

Shield Abilities (Sonic 3 & K)

Flame Shield

When Sonic does the Flame Shield special move, his X speed is set to 8 in the direction he is facing, and his Y speed is set to 0, regardless of their previous values.

Bubble Shield

When Sonic does the Bubble Shield bounce, his X speed is set to 0, and his Y speed to 8. When he rebounds from the ground, his Y speed is set to -7.5.

Electric Shield

When Sonic does the Electric Shield jump, his X speed is unaffected, but his Y speed is set to -5.5 regardless of its previous value.

Note: All of the Shield abilities can only be performed once in the air. Sonic must connect with the ground before he can perform them again.

Sonic's Insta-Shield

Considering the fact that the Insta-Shield does nothing to Sonic's xsp or ysp. It does however allow him to control a rolling jump.

Knuckles' Gliding/Climbing

When Knuckles first begins gliding, his X speed is set to 4 in the direction he is facing. Y speed is set to 0, but only if it was negative at the time, otherwise it is unaffected. X speed then accelerates by 0.015625 every step.

Gliding has a top speed of 24. This top speed is so high that it is unreachable anywhere in the game -- except for Mushroom Hill Zone Act 1, where Super/Hyper Knuckles can glide across the top of the level to achieve this speed.

During the glide, gravity is 0.125, which is weaker than usual. Also, unlike a normal jump, gravity is only added while Y speed is less than 0.5. If Y speed is higher than that (say Knuckles was falling quickly when he began to glide), gravity is subtracted from Y speed instead, slowing his descent.

if (ysp < 0.5) ysp += 0.125;
if (ysp > 0.5) ysp -= 0.125;

When you let go of the button, Knuckles drops, and his X speed is multiplied by 0.25. When he hits the ground, it is set to 0. While dropping from a glide, gravity is the normal value, 0.21875.

If you don't release the button, but allow Knuckles to glide into the ground and slide on his stomach, he has a friction value of 0.125 while sliding. He starts to stand up as soon as X speed reaches 0. If you release the button after he has begun to slide, X speed is set to 0 immediately, and he begins to stand up. Pressing Left or Right while sliding or standing up has no effect, but you can break into the standing up animation to jump if you press the jump button again.

If Knuckles hits a wall while gliding, he catches on, and can climb it. He will catch on even if he's turning around, as long as his X speed is still in the direction of the wall. He climbs up and down at a speed of 1. When Knuckles jumps off of a wall, his X speed is set to 4 in the opposite direction of the wall, and his Y speed is set to -4.

Note: Knuckles' knuckles deflect projectiles (just like the Shields do) while he is gliding.

Turning Around

When Knuckles is gliding, you can turn him around simply by tapping the Left or Right button. Even if you let go, he will continue to make a full turn. You can, however, reverse your decision and turn him back in the original direction before he makes a full turn.

You might think that turning around while gliding would be much like turning around while running on the ground. X speed would be steadily decreased until it reached zero, and then would start adding in the other direction. This is not the case, though, and a special method is used that preserves Knuckles' gliding speed.

When Knuckles is gliding, there is a value, which we'll call a, that is 0 when he's gliding to the right, and 180 when he's gliding to the left.

When Knuckles begins to turn, his X speed is stored - let's call the stored value t. If he's turning from the left to the right, a is decreased by 2.8125 until it reaches 0 (which takes 64 steps). If he's turning from right to left, a is increased by 2.8125 until it reaches 180. During the turn X speed is made to equal t times the cosine of a.

a += 2.8125 * -sign(t);
xsp = t * cosine(a);

So, no matter how fast Knuckles is gliding, he turns around in the same amount of time, and his speed reverses fully. During the turn, there is no acceleration. It kicks back in once he's finished turning all the way around.

Gliding Rebound

An interesting side-effect of the fact that Knuckles' Y speed is not immediately blunted when he begins gliding while falling quickly is the "Gliding Rebound". If you press the button to begin gliding just as Knuckles connects with an enemy or item monitor, his Y speed is reversed from the rebound just as he begins to glide. Since gliding gravity is weaker than standard gravity, he goes soaring up into the air. This is not necessarily a bug - it's actually kind of fun.

Once Knuckles is already gliding, rebound operates normally. Since he can't exceed a Y speed of 0.5 while gliding, though, the effect is rather weak.

Underwater

Strangely enough, Knuckles' gliding and climbing physics are totally unaffected by water. I suspect this is because the code performed when entering and exiting the water simply changes the acceleration, deceleration, and top speed constants (this is why falling in water nullifies Super Fast Shoes). Because Knuckles' gliding and climbing code operates irrespective of these values, his abilities couldn't be affected by water without rewriting the water entry and exit code. In your engine you may wish to halve some of Knuckles' speeds when submerged to be more realistic, unless you want to remain 100% true to the original games.

Tails' Helitail

When Tails begins to fly, his Y speed is unaffected. However, since Tails has to release the button in order to press it again to fly, he can't possibly fly up faster than -4.

While flying, the variables are much like a standard jump. He accelerates at 0.09375, and there is no separate deceleration value. The normal air drag calculation is performed, which means Tails can't fly horizontally as fast while moving upward than when moving downward. The air drag cancels out the acceleration at an X speed of 3. There is no air drag while moving down, though, so he can reach an X speed of 6, the normal maximum.

While flying, gravity is 0.03125. Pressing Up or Down doesn't decrease or increase it.

Pressing the button doesn't cause an immediate loss of Y speed (like a double-jump), but instead a temporary change in gravity. Gravity becomes -0.125, and remains so until Y speed is less than -1. Then gravity returns to normal in the next step and Tails begins to fly back down. If Y speed is already less than -1, pressing the button does nothing.

Tails can only fly for 480 frames, or 8 seconds, before getting tired. The only difference being tired makes (besides the pooped-out expression) is that pressing the button doesn't have any effect anymore. Gravity, and all other variables, remain the same.

Note: Tails' tails deflect projectiles (just like the Shields do) while he is flying.