Difference between revisions of "SPG:Player 2"
From Sonic Retro
m (→Actions: Clarity) |
m (Clarity) |
||
Line 33: | Line 33: | ||
Player 2 reads all the data from the entry ''16'' frames into the past. From this point on this guide, when Player 2 uses this information it will be labelled as '''target_inputs''', '''target_x''', '''target_y''', or '''target_grounded''', etc. These will be in reference to Player 1's state ''16'' frames in the past that was read from these lists. | Player 2 reads all the data from the entry ''16'' frames into the past. From this point on this guide, when Player 2 uses this information it will be labelled as '''target_inputs''', '''target_x''', '''target_y''', or '''target_grounded''', etc. These will be in reference to Player 1's state ''16'' frames in the past that was read from these lists. | ||
− | === | + | ===CPU Following State=== |
− | Before anything else happens, if Player 2 currently has an active [[SPG:Running#Control_Lock|control lock]] and their '''''Ground Speed''''' is ''0'', they are most likely stuck on a slope and they will enter their [[SPG:Player_2#CPU_Spindash_State|CPU Spindash state]]. This state will be explained up ahead. Otherwise, Player 2 will | + | Before anything else happens, if Player 2 currently has an active [[SPG:Running#Control_Lock|control lock]] and their '''''Ground Speed''''' is ''0'', they are most likely stuck on a slope and they will enter their [[SPG:Player_2#CPU_Spindash_State|CPU Spindash state]]. This state will be explained up ahead. Otherwise, Player 2 will continue onto [[SPG:Player_2#CPU Following State|CPU following]]. |
− | + | In the CPU Following state, Player 2 will decide upon their CPU controller inputs to adequately follow Player 1. Firstly, Player 2 will adopt the '''target_inputs''' found from Player 1's control list as their CPU inputs. These will potentially be modified up ahead, but if left unchanged, this means Player 2 will copy the Player exactly, with a 16 frame delay. | |
− | |||
Then, if Player 2 is not pushing or '''target_pushing''' is true, Player 2 will move onto normal movement. | Then, if Player 2 is not pushing or '''target_pushing''' is true, Player 2 will move onto normal movement. | ||
Line 102: | Line 101: | ||
====Spindash==== | ====Spindash==== | ||
− | Once Player 2 begins | + | Once Player 2 begins Spindashing, they will they will tap the {{A}}{{B}}{{C}} buttons on their CPU controller every ''32'' frames (checked on a global timer). |
− | Meanwhile, every ''128'' frames (checked on a global timer) the game will release the {{A}}{{B}}{{C}} buttons and down button on their CPU controller, releasing the Spindash. | + | Meanwhile, every ''128'' frames (checked on a global timer) the game will release the {{A}}{{B}}{{C}} buttons and down button on their CPU controller, releasing the Spindash. This will also switch the state back to CPU Following. |
==Respawning== | ==Respawning== |
Revision as of 04:36, 4 July 2023
Sonic Physics Guide |
---|
|
Collision |
|
Physics |
|
Gameplay |
Presentation |
Special |
Notes:
- The research applies to all four of the Sega Mega Drive games and Sonic CD.
Contents
Introduction
Starting with Sonic 2, a second player can follow you around the stage. At first glance it may seem like they simply copy your inputs, but there is a lot more nuance to the following Player's (Player 2's) actions.
Player 2 Control
By default, Player 2 is CPU controlled; however every time the Player 2 controller detects input, CPU control will be disabled for 10 seconds.
Player 2 CPU
When the Player 2 is CPU controlled and is following Player 1, they access various bits of information about Player 1's state from 16 frames in the past. How does it do this? Well, Players keep lists of their actions and states each frame.
State Lists
The information lists stored is as follows:
Position List |
The X/Y Position of the Player. |
---|---|
States List |
The grounded state, pushing state, jumping state and direction the player is facing. |
Control List |
The complete controller inputs being used. |
These lists are added to each frame by the Player. Each list is 32 entries long and therefore retains information from the last 32 frames.
Player 2 reads all the data from the entry 16 frames into the past. From this point on this guide, when Player 2 uses this information it will be labelled as target_inputs, target_x, target_y, or target_grounded, etc. These will be in reference to Player 1's state 16 frames in the past that was read from these lists.
CPU Following State
Before anything else happens, if Player 2 currently has an active control lock and their Ground Speed is 0, they are most likely stuck on a slope and they will enter their CPU Spindash state. This state will be explained up ahead. Otherwise, Player 2 will continue onto CPU following.
In the CPU Following state, Player 2 will decide upon their CPU controller inputs to adequately follow Player 1. Firstly, Player 2 will adopt the target_inputs found from Player 1's control list as their CPU inputs. These will potentially be modified up ahead, but if left unchanged, this means Player 2 will copy the Player exactly, with a 16 frame delay.
Then, if Player 2 is not pushing or target_pushing is true, Player 2 will move onto normal movement.
Otherwise, they will skip normal movement and move onto jump checking.
Normal Movement
In Sonic 2, normal movement will begin with the walking checks.
However, in Sonic 3, if Player 1's absolute Ground Speed is less than 4 and they are not standing on an object, 32 is subtracted from target_x. This only applies during normal movement.
Walking
Player 2 will then compare their X Position to target_x.
Actions
If Player 2 is in the air, and they are jumping, they will hold down the buttons on their CPU controller, and then exit the CPU following code for that frame. Otherwise, they will continue to check for more actions.
If the absolute distance between Player 2's X Position and target_x is larger than 64, Player 2 will exit the CPU following code for that frame. Otherwise, they will continue to check for more actions.
If target_y is equal to or greater than Player 2's Y Position, it will exit the CPU following code for that frame. Otherwise, if the target_y is more than 32 pixels above Player 2's Y Position, it will exit the CPU following code for that frame.
Otherwise, if the CPU following code has not been exited, it will move ahead onto the jump checking.
Jump Checking
Here, Player 2 simply checks for a jump once every 64 frames (checked on a global timer). On that frame, if they aren't crouching, they will press and hold the jump buttons on their CPU controller inputs, and then exit the following code.
CPU Spindash State
When in the CPU Spindash state, a few checks are performed.
Firstly, if control lock is active, the game will exit the CPU Spindash code for that frame, but will check again the next frame.
Crouching
Before the Player 2 can Spindash, they'll try to crouch.
Firstly, they'll check if their Ground Speed is 0. If it isn't, the game will exit the CPU Spindashing code for that frame.
They'll turn to face Player 1.
Then they will press and hold down the button on their CPU controller in order to crouch.
Meanwhile, the game is checking if they are finally in their ducking sprite. If they are, they will tap the buttons on their CPU controller to initiate the Spindash. However, at the same time every 128 frames (checked on a global timer) the game will check if Player 2 isn't yet crouching. If they are not, the game will cancel the CPU Spindash state entirely and set Player 2's state to the CPU Following state.
Spindash
Once Player 2 begins Spindashing, they will they will tap the buttons on their CPU controller every 32 frames (checked on a global timer).
Meanwhile, every 128 frames (checked on a global timer) the game will release the buttons and down button on their CPU controller, releasing the Spindash. This will also switch the state back to CPU Following.
Respawning
Player 2 will Respawn if they are offscreen for 300 frames.
Tails
In the case of Tails, when they respawn they'll begin flying back in.
Flying In
Horizontal
When flying in, Tails will decide how much to move their X Position by based on the difference in X Position and Player 1's X Speed.
x_difference = Player 2's X Position - target_x;
x_to_move = minimum(12, absolute(x_difference) >> 4) + absolute(Player 1's X Speed); // ">> 4" here is equivalent to dividing by 16, floored
Tails will face whichever direction target_x is in, and will move towards target_x by a distance of minimum(x_to_move, absolute(x_difference))
in that direction each frame.
Vertical
Vertically, they'll move up or down (modifying Y Position rather than using speeds) by 1 pixel per frame until they reach Player 1's Y Position.
Landing
They'll finally land when they are at the same X/Y Position as Player 1, after also making sure that Player 1 isn't in their dying state.