Actions

SPG:Main Game Loop

From Sonic Retro

Revision as of 13:10, 10 April 2021 by Lapper2 (talk | contribs) (Hitbox info)

Notes:

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.

  1. Check for special animations that prevent control (such as balancing).
  2. Check for starting a spindash.
  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.
    1. Which sensors are used varies based on the the sensor activation.
    2. Note: This occurs before Sonic's position physically moves, meaning he might not actually be touching the wall yet, the game accounts for this by adding Sonic's X Speed and Y Speed to the sensor's position.
  8. Check for starting a roll.
  9. Handle camera boundaries (keep Sonic inside the view and kill Sonic if he touches the kill plane).
  10. Move Sonic
    1. Update X Position and Y Position based on X Speed and Y Speed.
  11. Floor sensor collision occurs.
    1. Update Sonic's Ground Angle & position.
    2. Adhere 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.
    1. Which sensors are used varies based on the the sensor activation.
    2. Note: This occurs before Sonic's position physically moves, meaning he might not actually be touching the wall yet, the game accounts for this by adding Sonic's X Speed and Y Speed to the sensor's position.
  5. Handle camera boundaries (keep Sonic inside the view and kill Sonic if he touches the kill plane).
  6. Move Sonic
    1. Update X Position and Y Position based on X Speed and Y Speed.
  7. Floor sensor collision occurs.
    1. Update Sonic's Ground Angle & position.
    2. Adhere 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 Sonic 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 Sonic
    1. Update X Position and Y Position based on X Speed and Y Speed.
  6. Apply gravity.
    1. Update Y Speed by adding grv to it.
    2. Note: this happens after Sonic's position was updated. This is an important detail for ensuring Sonic's jump height is correct.
  7. Check underwater for reduced gravity.
  8. Rotate angle back to 0.
  9. All collision checks occurs here.
    1. The sensors used depend on the sensor activation.
    2. Wall collision occurs first.

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

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 the Player out rather than the Player object itself detecting them. Every object is different and execute their code in various orders.