An overview of physics in Sonic games. Parts 5 and 6: loss of rings and being under water
- Transfer

Continuation of the series of articles on physics in games about Sonic. This post discusses the loss of rings and being under water.
Links to other parts of the series:
Part 1: solid tiles
Part 2: running
Parts 3 and 4: jumps and rotation
Parts 7 and 8: springs and gizmos, super speeds
Part 5: the loss of rings
- 1 Ring Limitations
- 2 Broken rings
- 3 Gravity for rings
- 4 Bouncing rings
- 5 Time “life” rings
- 6 Reassembly of rings
- 7 Invulnerability
- 8 Ring Animations
- 9 Depth of drawing rings
Restrictions on the rings
When Sonic hits an opponent or dangerous obstacles, he loses all the rings that he has collected, but 32 rings fly apart in different directions. So Sonic cannot reassemble more than 32 rings, even if he had 100 of them.
Expansion of rings
Rings flying away from Sonic move along a certain path of two concentric circles, each of which contains no more than 16 rings. Rings in the first circle fly faster than rings in the second. Here is a formula for creating rings that can be converted to any programming language:
{
let t = 0
let angle = 101.25 ; где 0=справа, 90=сверху, 180=слева, 270=внизу
let n = false
let speed = 4
while t < количества колец
{
создать объект "скачущее кольцо"
установить вертикальную скорость кольца равной -sin(angle)*speed
установить горизонтальную скорость кольца равной cos(angle)*speed
if n = true
{
умножить горизонтальную скорость кольца на -1
увеличить угол на 22.5
}
let n = not n ; if n = false, n становится true, и наоборот
увеличить t на 1
if t = 16
{
let speed = 2 ; теперь мы на втором круге, так что уменьшаем скорость
let angle = 101.25 ; снова задаём угол
}
}
}
So, the first 16 rings move at a speed of 4 pixels per cycle, and the second 16 are twice as slow (2 pixels per cycle).
Gravity for rings
Rings do not use the same gravitational constant as Sonic. The value of their gravity is 0.09375. Therefore, this value is added every cycle to the vertical speed of the rings.
Bouncing rings
When flying rings touch the ground, their vertical speed is multiplied by a factor of -0.75. This leads to a change in the direction of their vertical movement, and also reduces speed. This calculation is performed after adding gravity. Bouncing rings does not affect their horizontal speed.
The bounce of the rings is calculated so roughly that it is almost annoying. But with a normal game this is actually imperceptible, and perhaps it was necessary to avoid the brakes. It seems they don’t check every cycle to see if they hit the ground, so sometimes they plunge pretty hard into the surface before deciding to bounce back. This behavior does not need to be emulated.
However, there are other restrictions for jumping rings, perhaps they are used to avoid processor load. The walls are completely unaffected by the walls, and they interact with vertical surfaces. In addition, they only check for collisions with the surface when they move down (i.e. when their vertical speed is positive). Therefore, they can even fly through the ceiling. Sometimes this can really be a problem for Sonic if he is hit in a small corridor, because most of the rings will fly to the ceiling and it will be impossible to assemble them again.
If I used a system more powerful than Genesis / Mega Drive, I would program the rings to check for horizontal collisions. In a collision, they must multiply their horizontal speed by a factor of -0.25. They should also check for collisions with ceilings to determine if a collision occurred while moving up or down. If they moved down, they should bounce, as usual, but if they moved up, they should reset their vertical speed. This would be more merciful to the player, since most of the rings would not be lost when trying to reassemble.
“Life” of rings
All flying rings are destroyed after 256 cycles if they were not reassembled. They are also destroyed when going beyond the horizontal borders of the screen. And, again, on a more powerful system, such behavior can not be emulated.
Reassembling the rings
After hitting Sonic needs 64 cycles before he can reassemble the flying rings.
Invulnerability
After impact, Sonic becomes invulnerable for a short period of time. This invulnerability lasts until Sonic flies away from the impact, and then another 120 cycles after the resumption of movement. During these 120 cycles, it flickers, disappearing and appearing every 4 cycles.
Ring animations
Hanging rings in place have 4 frames of animation, and change frames every 8 cycles. The behavior of flying rings is more complicated, because they have a higher animation speed when creating, but over time it decreases. At the beginning, animation frames change every 2 cycles, but at the end they slow down and change every 16 cycles or so. I do not know the exact values yet. Flying rings are created with one starting frame of the animation - the ring is visible in its entirety.
Depth of drawing rings
Both flying and hanging rings have a greater depth than Sonic, that is, they are drawn behind it. But they have a shallower depth, that is, they draw over it when they turn into sparks.

Part 6: being under water
When Sonic is under water, he moves more slowly, but in general the physics remains the same. This is mainly achieved by dividing the corresponding variables in half, but some, such as gravity and the initial jump speed, are not exactly equal to half.
Variables
Acceleration
Acceleration is half the normal value: 0.0234375.
Slowdown
Slowdown is half the normal value: 0.25.
Slow during rotation remains unchanged.
Friction
force The friction force is half the normal value: 0.0234375.
The friction force during rotation is 0.01171875.
Maximum speed The
maximum running speed of Sonic is 3, half of the usual value.
Acceleration in the air
Acceleration in the air acts in the usual way, but has the value 0.046875, two times less than usual.
Gravity
Gravity is 0.0625. Thanks to this, Sonic falls much more slowly.
Jump speed The
initial jump speed is -3.5 (-3 for Knuckles), the speed at the time of separation from the ground is -2.
Bubbles
When Sonic collides with a bubble underwater, both X and Y speeds equal 0.
Entrance and exit
When Sonic falls into the water, his horizontal speed is multiplied by 0.5, and the vertical speed is multiplied by 0.25 (this happens after adding gravity). Conversely, when Sonic jumps out of the water, his vertical speed doubles (after adding the “water” gravity value) and he starts to move faster because the water no longer affects his movement (however, leaving the water does not affect the horizontal speed).
Drowning
When Sonic sinks, his X and Y speeds both become equal to 0, and “water” gravity remains normal.
Speed Shoes
If Sonic is wearing Speed Shoes and he gets under water, water variables have a greater effect, thus nullifying all the effects of Speed Shoes. No calculations, such as multiplying by 0.5, are performed.
Animation speeds
Diving under water does not affect the speed of Sonic's animation. Animations whose speeds are proportional to variables that change, such as Sonic's speed, change automatically in the same proportion.
PS for attentive and curious readers. In this series of posts there is a small Easter egg, namely, two encrypted English words. Each part contains exactly one letter (that is, 6 letters can now be decrypted), there will be 14 of them, as well as parts. In the next posts I will post hints, but for now the first: the code is not in HTML, no steganography and mysterious third-party sites. You can send your guesses in PM, for read-onlly and just readers in a profile there is my mail. The first guesser will be some nice bonus (for example, the translation of an interesting article for him). (I hope such riddles are not against Habr's rules)
