Difference between revisions of "SPG:Main Game Loop"
From Sonic Retro
(Created game loop page detailing the main order of key events, split from solid tiles for greater focus and easy locating.) |
(Formatting & readability) |
||
Line 10: | Line 10: | ||
Their main events depend on their current state. | Their main events depend on their current state. | ||
+ | |||
+ | Note: ''While the main lists below are in order, the sub lists, though also numbered, are merely descriptive.'' | ||
+ | <div class="large-12 columns"> | ||
+ | <div class="large-4 columns"> | ||
===While Normal=== | ===While Normal=== | ||
"Normal" means when Sonic is not airborne or rolling. | "Normal" means when Sonic is not airborne or rolling. | ||
− | + | # Check for special animations that prevent control (such as balancing). | |
− | + | # Check for starting a spindash. | |
− | + | # Adjust ''gsp'' based on current ''ang'' ([[SPG:Slope_Physics#Slope_Factor|Slope Factor]]). | |
− | + | # Check for starting a jump. | |
− | + | # Update ''gsp'' based on directional input and apply friction/deceleration. | |
− | + | # Check for starting ducking, balancing on ledges, etc. | |
− | + | # [[SPG:Solid_Tiles#Wall_Sensors_.28E_and_F.29|Wall sensor collision]] occurs. | |
− | + | ## Which sensors are used varies based on the the [[SPG:Solid_Tiles#While_Grounded|sensor activation]]. | |
− | + | ## Note: ''This occurs before Sonic's position physically moves, meaning he might not actually be touching the wall yet. So it will check if the distance to a wall is closer than Sonic's ''xsp'' in a given direction using the wall sensor's extension. If the distance returned by the sensor is less than Sonic's ''xsp'', he will collide.'' | |
− | + | # Check for starting a roll. | |
− | + | # Handle camera boundaries (keep Sonic inside the view and kill Sonic if he touches the kill plane). | |
− | + | # Move Sonic | |
− | + | ## Update ''xpos'' and ''ypos'' based on ''xsp'' and ''ysp''. | |
− | + | # [[SPG:Solid_Tiles#Floor_Sensors_.28A_and_B.29|Floor sensor collision]] occurs. | |
− | + | ## Update Sonic's angle & position. | |
− | + | ## Adhere to level of terrain or become airborne if none found/too low. | |
+ | # Check for falling when ''gsp'' is too low on walls/ceilings. | ||
+ | </div> | ||
+ | <div class="large-4 columns"> | ||
===While Rolling=== | ===While Rolling=== | ||
− | + | # Adjust ''gsp'' based on current ''ang'' ([[SPG:Slope_Physics#Slope_Factor|Rolling Slope Factors]]). | |
− | + | # Check for starting a jump. | |
− | + | # Update ''gsp'' based on directional input and apply [[SPG:Running#Friction|friction]]. | |
− | + | # [[SPG:Solid_Tiles#Wall_Sensors_.28E_and_F.29|Wall sensor collision]] occurs. | |
− | + | ## Which sensors are used varies based on the the [[SPG:Solid_Tiles#While_Grounded|sensor activation]]. | |
− | + | ## Note: ''This occurs before Sonic's position physically moves, meaning he might not actually be touching the wall yet. So it will check if the distance to a wall is closer than Sonic's ''xsp'' in a given direction using the wall sensor's extension. If the distance returned by the sensor is less than Sonic's ''xsp'', he will collide.'' | |
− | + | # Handle camera boundaries (keep Sonic inside the view and kill Sonic if he touches the kill plane). | |
− | + | # Move Sonic | |
− | + | ## Update ''xpos'' and ''ypos'' based on ''xsp'' and ''ysp''. | |
− | + | # [[SPG:Solid_Tiles#Floor_Sensors_.28A_and_B.29|Floor sensor collision]] occurs. | |
− | + | ## Update Sonic's angle & position. | |
+ | ## Adhere to level of terrain or become airborne if none found/too low. | ||
+ | # Check for falling when ''gsp'' is too low on walls/ceilings. | ||
+ | </div> | ||
+ | <div class="large-4 columns"> | ||
===While Airborne=== | ===While Airborne=== | ||
"Airborne" means when Sonic is falling or jumping or otherwise not grounded. | "Airborne" means when Sonic is falling or jumping or otherwise not grounded. | ||
− | + | # Check for jump button release ([[SPG:Jumping#Jump_Velocity|variable jump velocity]]). | |
− | + | # Check for turning Super. | |
− | + | # Update ''xsp'' based on directional input. | |
− | + | # Apply [[SPG:Jumping#Air_Drag|air drag]]. | |
− | + | # Move Sonic | |
− | + | ## Update ''xpos'' and ''ypos'' based on ''xsp'' and ''ysp''. | |
− | + | # Apply [[SPG:Jumping#Gravity|gravity]]. | |
− | + | ## Update ''ysp'' by adding ''grv'' to it. | |
− | + | ## Note: ''this happens after Sonic's position was updated. This is an important detail for ensuring Sonic's jump height is correct.'' | |
− | + | # Check underwater for reduced gravity. | |
+ | # Rotate angle [[SPG:Slope_Physics#Air_Rotation|back to 0]]. | ||
+ | # All collision checks occurs here. | ||
+ | ## The sensors used depend on the [[SPG:Solid_Tiles#While_Airborne|sensor activation]]. | ||
+ | ## Wall collision occurs first. | ||
+ | </div> | ||
+ | </div> | ||
After this, the special objects are executed. | After this, the special objects are executed. | ||
Line 66: | Line 83: | ||
==General Objects== | ==General Objects== | ||
− | |||
− | As stated in [[SPG:Game_Objects|Game Objects]], solid objects push | + | Object movement and collision occurs here. |
+ | Player collision with objects happens here too. As stated in [[SPG:Game_Objects|Game Objects]], solid objects push Sonic out rather than Sonic himself detecting them. | ||
+ | Every object is different and execute their code in various orders. | ||
[[Category:Sonic Physics Guide]] | [[Category:Sonic Physics Guide]] |
Revision as of 08:33, 14 December 2020
Notes:
- The research applies to all four of the Sega Mega Drive games and Sonic CD.
Contents
Introduction
In order to gain a full picture of how Sonic games work, as well as knowing what physically happens the order of events is just as important.
Characters
Characters are the first objects to run their code.
Their main events depend on their current state.
Note: While the main lists below are in order, the sub lists, though also numbered, are merely descriptive.
While Normal
"Normal" means when Sonic is not airborne or rolling.
- Check for special animations that prevent control (such as balancing).
- Check for starting a spindash.
- Adjust gsp based on current ang (Slope Factor).
- Check for starting a jump.
- Update gsp based on directional input and apply friction/deceleration.
- Check for starting ducking, balancing on ledges, etc.
- Wall sensor collision occurs.
- Which sensors are used varies based on the the sensor activation.
- Note: This occurs before Sonic's position physically moves, meaning he might not actually be touching the wall yet. So it will check if the distance to a wall is closer than Sonic's xsp in a given direction using the wall sensor's extension. If the distance returned by the sensor is less than Sonic's xsp, he will collide.
- Check for starting a roll.
- Handle camera boundaries (keep Sonic inside the view and kill Sonic if he touches the kill plane).
- Move Sonic
- Update xpos and ypos based on xsp and ysp.
- Floor sensor collision occurs.
- Update Sonic's angle & position.
- Adhere to level of terrain or become airborne if none found/too low.
- Check for falling when gsp is too low on walls/ceilings.
While Rolling
- Adjust gsp based on current ang (Rolling Slope Factors).
- Check for starting a jump.
- Update gsp based on directional input and apply friction.
- Wall sensor collision occurs.
- Which sensors are used varies based on the the sensor activation.
- Note: This occurs before Sonic's position physically moves, meaning he might not actually be touching the wall yet. So it will check if the distance to a wall is closer than Sonic's xsp in a given direction using the wall sensor's extension. If the distance returned by the sensor is less than Sonic's xsp, he will collide.
- Handle camera boundaries (keep Sonic inside the view and kill Sonic if he touches the kill plane).
- Move Sonic
- Update xpos and ypos based on xsp and ysp.
- Floor sensor collision occurs.
- Update Sonic's angle & position.
- Adhere to level of terrain or become airborne if none found/too low.
- Check for falling when gsp is too low on walls/ceilings.
While Airborne
"Airborne" means when Sonic is falling or jumping or otherwise not grounded.
- Check for jump button release (variable jump velocity).
- Check for turning Super.
- Update xsp based on directional input.
- Apply air drag.
- Move Sonic
- Update xpos and ypos based on xsp and ysp.
- Apply gravity.
- Update ysp by adding grv to it.
- Note: this happens after Sonic's position was updated. This is an important detail for ensuring Sonic's jump height is correct.
- Check underwater for reduced gravity.
- Rotate angle back to 0.
- All collision checks occurs here.
- The sensors used depend on the sensor activation.
- Wall collision occurs first.
After this, the special objects are executed.
Special objects
Next, objects executed are those which setup certain special events, like title cards.
After this, general objects are executed.
General Objects
Object movement and collision occurs here. Player collision with objects happens here too. As stated in Game Objects, solid objects push Sonic out rather than Sonic himself detecting them. Every object is different and execute their code in various orders.