Actions

SPG:Air State

From Sonic Retro

Revision as of 11:15, 19 July 2021 by LapperDev (talk | contribs) (Cleanup and consistency, added SPG table of contents)
Sonic Physics Guide
Collision
Physics
Gameplay
Presentation
Special

Notes:

Introduction

Any time the Player is in the air, they don't have to worry about angles, Ground Speed, slp, or any of that jazz. All they have to do is move using X Speed and Y Speed until they detect the ground, at which point they re-enter the ground state.

While the player is on the ground, X Speed and Y Speed are constantly being updated using the groundspeed, so when the player Jumps or otherwise leaves the floor, X Speed and Y Speed are already set, ready for air motion.

Air Acceleration

When the Player is airborne, they can accelerate twice as fast as on land (air).

There is no friction in the air (but there is a complicated drag effect that will be explained later), and pretty much, once the Player has a certain X Speed in the air, they'll just keep going at that speed until you tell them otherwise or they hit a wall.

Furthermore, there is no distinction for deceleration in the air, either, so pressing Left simply subtracts air from X Speed no matter what, and pressing Right adds air to X Speed.

Sonic's top speed (top) is the same in the air as on the ground.

Gravity

Gravity (grv) is added to Y Speed in every step in which the Player isn't on the ground. It's what makes them fall downward when they run off of cliffs. It's also what stops them from moving upward forever when they jump.

Top Y Speed

In Sonic 1, the Player's Y Speed does not seem to be limited. As they fall, grv continues to be added to Y Speed, increasing indefinitely.

In Sonic CD, however, a limit was introduced so that Y Speed does not exceed 16 pixels per step. This limit is important so that the Player never outruns the camera, or passes through solid ground because they're moving so fast per step that they never even collide with it. Most likely introduced in Sonic CD because of the increased height in the design of levels such as Collision Chaos, and the endless vertical shaft in Tidal Tempest. Without the limit, the Player would accelerate to ridiculous velocities in some of these areas and probably break the game.

Y Speed += grv
if (Y Speed > 16) Y Speed = 16

Air Drag

Each step the Player is in the air, a special formula is performed on their X Speed, but only if certain conditions are met: Y Speed must be negative and Y Speed must be more than -4 (e.g. -3, or -3.5, is "more" than -4).

if (Y Speed < 0 && Y Speed > -4)
{
    X Speed -= ((X Speed div 0.125) / 256);
}

Air drag is calculated each step before grv is added to Y Speed.

Air Rotation

When the Player leaves a slope, such as running up and off a quarter pipe, the Players's Ground Angle smoothly returns to 0.

The Player's Ground Angle changes by

 2.8125° (2) ($2)

each frame, in the direction towards 0.


  • Note: Degree angle is approximate, as the original game has angles ranging up to 256. Degree, decimal, and hex have been provided.
  • Note: Regardless of the Player's Ground Angle, their airborne sensors do not rotate. Air collision essentially ignores the Player's angle and treats it as floor mode at all times.