Actions

SPG:Main Game Loop

From Sonic Retro

Revision as of 09:52, 25 February 2023 by LapperDev (talk | contribs) (Collision With Player: Specificly solid)
Sonic Physics Guide
Collision
Physics
Gameplay
Presentation
Special

Notes:

Introduction

In order to gain a full picture of how classic Sonic games work, the order of events is just as important as knowing what physically happens during them;

Characters

Characters are the first objects to run their code.

Their main events depend on their current state.

While Normal

"Normal" means when the Player is not airborne or rolling.

  1. Check for special animations that prevent control (such as balancing).
  2. Check for starting a spindash while crouched.
  3. Adjust Ground Speed based on current Ground Angle (Slope Factor).
  4. Check for starting a jump.
  5. Update Ground Speed based on directional input and apply friction/deceleration.
  6. Check for starting ducking, balancing on ledges, etc.
  7. Wall sensor collision occurs.
    • Which sensors are used varies based on the the sensor activation.
    • This occurs before the Player's position physically moves, meaning they might not actually be touching the wall yet, the game accounts for this by adding the Player's X Speed and Y Speed to the sensor's position.
  8. Check for starting a roll.
  9. Handle camera boundaries (keep the Player inside the view and kill them if they touch the kill plane).
  10. Move the Player object
    • Updates X Position and Y Position based on X Speed and Y Speed.
  11. Floor sensor collision occurs.
    • Updates the Player's Ground Angle & position.
    • Adhere the Player to (snap to) level of terrain or become airborne if none found/too low.
  12. Check for falling when Ground Speed is too low on walls/ceilings.

While Rolling

  1. Adjust Ground Speed based on current Ground Angle (Rolling Slope Factors).
  2. Check for starting a jump.
  3. Update Ground Speed based on directional input and apply friction.
  4. Wall sensor collision occurs.
    • Which sensors are used varies based on the the sensor activation.
    • This occurs before the Player's position physically moves, meaning he might not actually be touching the wall yet, the game accounts for this by adding the Player's X Speed and Y Speed to the sensor's position.
  5. Handle camera boundaries (keep the Player inside the view and kill them if they touch the kill plane).
  6. Move the Player object
    • Update X Position and Y Position based on X Speed and Y Speed.
  7. Floor sensor collision occurs.
    • Updates the Player's Ground Angle & position.
    • Adhere the Player to (snap to) level of terrain or become airborne if none found/too low.
  8. Check for falling when Ground Speed is too low on walls/ceilings.

While Airborne

"Airborne" means when the Player is falling or jumping or otherwise not grounded.

  1. Check for jump button release (variable jump velocity).
  2. Check for turning Super.
  3. Update X Speed based on directional input.
  4. Apply air drag.
  5. Move the Player object
    • Updates X Position and Y Position based on X Speed and Y Speed.
  6. Apply gravity.
    • Update Y Speed by adding grv to it.
    • This happens after the Player's position was updated. This is an important detail for ensuring the Player's jump height is correct.
  7. Check underwater for reduced gravity.
  8. Rotate angle back to 0.
  9. All collision checks occurs here.

Hitbox

After moving, the Player will check for nearby object hitboxes for overlap with theirs. It it important to note this happens from the Player's code, so before any objects run their code or act solid.

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 for things like enemies, bosses, gimmicks and any other objects found in a zone and their collisions with the terrain occur here.

The things listed below are in no particular order. Every object is coded separately and execute their code and actions in various orders within their routines.

Actions And Movement

General game objects run their various routines with actions in whatever order they are designed with. Their position could be the first thing to update, or it could be the last. They could update their X Speed and Y Speed before or after the position updates. It depends on the object.

See Game Objects and Game Enemies for descriptions of the actions that general objects will execute here.

Solid Collision With Player

Player object collision with general objects happens here too. As stated in Solid Objects, solid objects run their own code to push the Player out rather than the Player object itself detecting them. This allows the game to run less code per frame, because the player isn't checking every object before object's are looped to run their own code. Player collision with an object could happen anywhere in an object's routine, also.

Trigger Areas

If the object uses a trigger area, overlap with that will be checked somewhere within the object's code, using the Player's current position.

Order Of General Objects

General objects themselves can be processed in any kind of order, objects are loaded into available memory at any time as they are needed. So an order or priority of general objects isn't really accounted for.