SPG:Underwater
From Sonic Retro
Sonic Physics Guide |
---|
|
Collision |
|
Physics |
|
Gameplay |
Presentation |
Special |
Notes:
- 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
Contents
Air
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:
Air Event
Each air event, the following happens:
Air Check
Firstly, remaining_air is checked. At certain air values, different actions will be performed:
- [25, 20, 15] a warning chime is sounded.
- [12] 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).
- [ Lower than 0] Sonic drowns.
Air Decrease
Secondly, 1 is subtracted from remaining_air.
Small Breathing Bubbles
Thirdly, small breathing bubbles are emitted from the Player's mouth.
Small 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 small breathing bubbles is either 1 or 2, chosen at random (the is an equal chance of either amount). If the number of small breathing bubbles is 2, the second will spawn at a random interval between 1 to 16 frames later.
Notes:
- 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 small breathing bubbles that spawn will move to the right by 4 pixels per frame.
- In Sonic 3, These bubbles specifically move up twice as fast as the bubbles that come from the Bubble generator object.
Count Down Warning
If at the current air event a countdown bubble is to be emitted, this countdown bubble will be spawned as if it were one of the small breathing bubbles from the Player's mouth.
If only 1 small breathing bubble is emitted, that must be the number bubble. If 2 small breathing bubbles are to be emitted, there is a quarter chance that the first will be the countdown bubble, otherwise the second small breathing bubble must be the countdown bubble.
When on of these are spawned, they act like a normal breathing bubble until a frame before the number forms from the bubble. After this point, their position gets locked in place and stays on screen until the animation ends.
var origin = Vector2.ZERO;
if frame is before the number forming{
// Normal bubble movement code goes here.
}else{
if frame is when the number is forming{
origin = position - camera.position; // Distance between object and camera in world space.
}
position = camera.position + origin;
// Stick objects position to the camera, so that its always present on screen.
}
The frame duration of countdown bubbles is 5 frames per sub-frame. The fully formed number will appear 4 times before the animation ends.
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.
Physics
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.
Water Entry and Exit
When the Player enters the water, and the player doesn't have any Control Flags (Such as having object collisions disabled, inputs disabled, normal animations being disabled, etc.) , their X Speed is divided by 2, and their Y Speed is divided by 4, quartering it (this occurs after gravity_force is added to Y Speed).
When the Player exits the water, A few check happen before speeds are altered. First, the player must not have any Control Flags, like in the entry condition, and if the player isn't currently being knocked back from taking damage. Then, if the previous is true, it checks if the players Y Speed is greater than -4 (The same value as player's jump release speed). If all these conditions are true, Y Speed is doubled (after water gravity_force has been added), (however, X Speed is not affected when leaving the water). If the Player is being controlled by another object (like being carried by Tails), Y Speed will not be affected.
Also, if the Player's Y Speed is less than -16 it will be limited to -16 upon exiting.
Constants
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)
Getting Hit
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.
Bubbles
When the Player gets a bubble underwater, their X Speed and Y Speed are both set to 0.
Speed Shoes
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.
Drowning
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.
Drowning Bubbles
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.
Animation Speeds
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.