From Sonic Retro
|Sonic Physics Guide|
- The research applies to all four of the Sega Mega Drive games and Sonic CD.
- For information about the Air Bubble Maker object and the physics of water bubbles, see Game Objects
While underwater, the Player can last 30 seconds before drowning. The Player's air value (we'll call this remaining_air) starts at a value of 30 upon entering the water. As you would imagine, once remaining_air reaches 0, the Player will drown.
This value represents the amount of seconds of air the Player has left. Meanwhile, a timer counts down from 60 each second. Each time this timer reaches 0, the "air event" occurs:
Each air event, the following happens:
Firstly, remaining_air is checked. At certain air values, different actions will be performed:
- [25, 20, 15] a warning chime is sounded.
-  the drowning music begins.
- [12, 10, 8, 6, 4, 2] a warning number bubble (the count down) will be emitted (these will be the numbers 5, 4, 3, 2, 1, or 0).
-  Sonic drowns.
Secondly, 1 is subtracted from remaining_air.
Thirdly, small bubbles are emitted from the Player's mouth. We'll call these "breathing bubbles".
Breathing bubbles spawn at the Player's X Position + 6 (or X Position - 6 when facing left) and at the Player's Y Position.
The number of breathing bubbles is either 1 or 2, chosen at random (the is an equal chance of either amount). If the number of breathing bubbles is 2, the second will spawn at a random interval between 1 to 16 frames later.
- The sine movement of the bubble is adjusted based on the way the Player is facing to ensure the bubble begins by moving away from the Player's mouth.
- When moving through a water tunnel like those in Labyrinth Zone, the breathing bubbles that spawn will move to the right by 4 pixels per frame.
Count Down Warning
If at the current air event a warning number bubble is to be emitted, this warning bubble will be spawned as of one of the breathing bubbles from the Player's mouth.
If only 1 breathing bubble is emitted, that must be the number bubble. If 2 breathing bubbles are to be emitted, there is a quarter chance that the first will be the warning bubble, otherwise the second breathing bubble must be the warning bubble.
Large Air Bubbles
When a large air bubble is breathed, the Player's remaining_air is reset to 30 and the timer is reset to 60. Any drowning music is cancelled. Note:
- For the collision and mechanics of bubbles, see Game Objects.
When the Player is underwater their speeds are modified to that they move much more slowly, but otherwise the physics are largely the same. This is achieved mostly by halving the pertinent variables, but some, like gravity and initial jump velocity, are not exactly half.
acceleration_speed: 0.0234375 (half of 0.046875) deceleration_speed: 0.25 (half of 0.5) friction_speed: 0.0234375 (half of 0.046875) top_speed: 3 (half of 6) air_acceleration_speed: 0.046875 (half of 0.09375) roll_friction_speed: 0.01171875 (half of 0.0234375) roll_deceleration_speed: 0.125 (unchanged) gravity_force: 0.0625 (instead of 0.21875) jump_force: 3.5 (3 for knuckles) (instead of 6.5 (6 for knuckles)) jump_release: -2 (instead of -4)
When getting hit underwater, the Player will fly back with an X Speed of 1 (or -1) and a Y Speed of -2, half that of normal.
When the Player gets a bubble underwater, their X Speed and Y Speed are both set to 0.
Entry & Exit
When the Player enters the water, their X Speed is multiplied by 0.5 and their Y Speed is multiplied by 0.25 (this occurs after gravity_force is added to Y Speed). Conversely, when the Player exits the water, their Y Speed is doubled (after water gravity_force has been added), (however, X Speed is not affected when leaving the water).
When in possession of Speed Shoes, but also underwater, the underwater variables take over, effectively nullifying the Speed Shoes altogether. No calculations, such as multiplying by 0.5, take place.
When the Player drowns, their X Speed and Y Speed are both set to 0, and the gravity_force remains set to the lower water gravity.
When drowning, 11 bubbles are created from the Player's mouth as they fall offscreen. The first bubble can spawn from 0 to 15 frames after drowning, chosen at random. Subsequent bubbles spawn 1 to 8 frames apart, also chosen at random.
Each of the 11 bubbles has a quarter chance of being a medium bubble, otherwise it will be a small bubble.
Being submerged doesn't affect the speed of the Player's animations at all. Variable Speed Animations will be attenuated by the same proportion automatically.