Actions

Difference between revisions of "SPG:Running"

From Sonic Retro

(accuracy and more consistent demographic (70 year olds aren't reading this))
m (it's 4, not 4.5)
Line 98: Line 98:
 
===Braking Animation===
 
===Braking Animation===
  
Sonic enters his braking animation when you turn around only if his absolute ''gsp'' is equal to or more than 4.5. In Sonic 1 and Sonic CD, he then stays in the braking animation until ''gsp'' reaches zero or changes sign. In the other 3 games, Sonic returns to his walking animation after the braking animation finishes displaying all of its frames.
+
Sonic enters his braking animation when you turn around only if his absolute ''gsp'' is equal to or more than 4. In Sonic 1 and Sonic CD, he then stays in the braking animation until ''gsp'' reaches zero or changes sign. In the other 3 games, Sonic returns to his walking animation after the braking animation finishes displaying all of its frames.
  
 
===Character Specific===
 
===Character Specific===

Revision as of 09:33, 19 August 2019

Notes:

Research applies to all four of the Sega Mega Drive games, and Sonic CD.

The following describes ground speed, the forces that impact it and the effects of player input. It only applies when Sonic is on dry land with no special power-ups. Curves, water physics, Super Sonic, and Speed Shoes will be covered in separate guides.

Variables

The following variables/constants will be referenced frequently in this section.

//Variables
xsp: the speed in which sonic is moving horizontally
ysp: the speed in which sonic is moving vertically
gsp: the speed in which sonic is moving on the ground	
//Constants
acc: 0.046875
dec: 0.5
frc: 0.046875 (same as acc)
top: 6

Ground Speed Conversion

gsp is used to calculate xsp and ysp when landed on normal ground. This is further described in The Three Speed Variables.

xsp = gsp*cos(angle);
ysp = gsp*-sin(angle);

Movement Rules

Note: In the original games, holding Left and Right at the same time will run both direction's code in one step, if you want in your engine, you can disable Left + Right input (Emulators like Fusion will just cancel the right input if left is also held).

Acceleration

If you're holding Left, Sonic's gsp decreases by acc every step. If you're holding Right (Also applies if you're holding Left, which you may not want in your engine), his gsp increases by acc every step.

Deceleration

If Sonic is already moving when you press Left or Right, rather than at a standstill, the computer checks whether you are holding the direction he's already moving. If so, acc is added to his gsp as normal. However if you are pressing in the opposite direction than he's already moving, the deceleration constant (dec) is added instead. Thus Sonic can turn around quickly. If no distinction is made between acc and dec, Sonic takes too long to overcome his current velocity, frustrating the player. A good engine must not make such a day one mistake.

One might think that if gsp happened to equal 0.1, and you pressed Left, dec would be subtracted, resulting in an gsp value of -0.4. Oddly, this is not the case in any of the original games. Instead, at any time an addition or subtraction of dec results in gsp changing sign, gsp is set to 0.5. For example, in the instance above, gsp would become -0.5. The bizarre result of this is that you can press Left for one step, and then press Right (or vice versa), and start running faster than if you had just pressed Right alone! Now, the resulting speed is still lower than one pixel per step, so it isn't very noticeable, but nonetheless it is true.

Friction

If you are not pressing Left or Right, friction (frc) kicks in. In any step in which the game recieves no horizontal input, frc is subtracted from gsp (depending on the sign of gsp), where if it then passes over 0, it's set back to 0.

Top Speed

Sonic can only accelerate up to a certain point. At some point, he reaches top speed and can no longer move any faster under his own power. So, after acc is added to gsp, if gsp exceeds top it's set to top.

In Sonic 1, if Sonic is already running at a higher speed than he can possibly achieve on his own (such as having been impelled by a spring), if you press in the direction he's moving, the computer will add acc to gsp, notice that gsp exceeds top, and set gsp to top. Thus it is possible to curtail your forward momentum by pressing in the very direction of your motion. This can be solved in your engine (and was fixed in Sonic 2 and beyond) by checking to see if gsp is less than top before adding acc. Only if gsp is already less than top will it check if gsp exceeds top.

Sonic CD and Sonic 2 actually has a fix like this, where the top check won't happen if gsp is already above top, because in Sonic CD can perform the "Super Peel Out", which launches him above his typical top, and in Sonic 2 because it's supposed to be a much faster game. The issue is, in both games, it doesn't fix this error when Sonic is in mid-air, causing him to usually lose his speed when running off of a ledge.

Here's some code logic that can accurately emulate movement and friction:

if (the player is pressing left)
{
    if (gsp > 0)
    {
        gsp -= dec;
        if (gsp <= 0)
            gsp = -0.5;
    }
    else if (gsp > -top)
    {
        gsp -= acc;
        if (gsp <= -top)
            gsp = -top;
    }
}

if (the player is pressing right)
{
    if (gsp < 0)
    {
        gsp += dec;
        if (gsp >= 0)
            gsp = 0.5;
    }
    else if (gsp < top)
    {
        gsp += acc;
        if (gsp >= top)
            gsp = top;
    }
}

if (the player is not pressing left or right)
    gsp -= minimum(absolute(gsp), frc) * sign(gsp);

Animation Rules

Running Animation

If you include Sonic CD in the mix, Sonic has 3 different running animations. He is depicted as standing still only if gsp is exactly zero. If he has any gsp whatsoever, he enters his walking animation, the frame advences in relation to his ground speed.

Once his gsp equals (or exceeds) 6, he enters his running animation, with the whirling feet. Once his gsp equals (or exceeds) 10, he enters his Dashing animation, with the figure-eight feet. Of course, the Dashing animation is only in Sonic CD.

Braking Animation

Sonic enters his braking animation when you turn around only if his absolute gsp is equal to or more than 4. In Sonic 1 and Sonic CD, he then stays in the braking animation until gsp reaches zero or changes sign. In the other 3 games, Sonic returns to his walking animation after the braking animation finishes displaying all of its frames.

Character Specific

All the characters - Sonic, Tails, and Knuckles - have the same acceleration, deceleration, top speed, running and braking values. They handle identically, with no difference at all besides their special moves and their sprites (and the annoying fact that Knuckles jumps lower than the other two).