Actions

Difference between revisions of "SPG:Solid Terrain"

From Sonic Retro

(Notes section, noting true in-game values of layers/priorities on the guide)
m (Minor additions/corrections)
Line 71: Line 71:
 
If that condition is met, it will then check if the Player has crossed the threshold.  
 
If that condition is met, it will then check if the Player has crossed the threshold.  
  
Note: ''We will use the example of a vertical switcher here, but a vertical switcher works exactly the same in the other axis.''
+
Note: ''We will use the example of a vertical switcher here, but a horizontal switcher works exactly the same in the other axis.''
  
 
If '''current_side''' is the left:
 
If '''current_side''' is the left:
Line 92: Line 92:
 
The result of this system is that the Player's layer is only switched when the switcher threshold is crossed. It works no matter how fast the Player is moving.  
 
The result of this system is that the Player's layer is only switched when the switcher threshold is crossed. It works no matter how fast the Player is moving.  
  
Additionally, because '''current_side''' is always updated even when the Player is out of radius range, if the Player jumps over (or otherwise moves around) a switcher it won't trigger, even when they enter back into the range on the other side.
+
Additionally, because '''current_side''' is always updated even when the Player is outside of the switcher range, if the Player jumps over (or otherwise moves around) a switcher it won't trigger, even when they enter back into the range on the other side.
  
  
Line 117: Line 117:
 
==Notes==
 
==Notes==
 
*''On this guide and in it's images, layer labels [A, B] and priority labels [L, H] represent values [0, 1] respectively in the original games.''
 
*''On this guide and in it's images, layer labels [A, B] and priority labels [L, H] represent values [0, 1] respectively in the original games.''
 +
*''This page is essentially part 2 of 2. This details how Solid Tiles and collision layers are used to create anything from simple slopes all the way to bigger Sonic set-pieces like loops. For part 1, describing what Solid Tiles are and how they are used directly, go to [[SPG:Solid_Tiles|Solid Tiles]]''.
 
[[Category:Sonic Physics Guide]]
 
[[Category:Sonic Physics Guide]]

Revision as of 07:22, 23 November 2022

Sonic Physics Guide
Collision
Physics
Gameplay
Presentation
Special

Notes:

  • The research applies to all four of the Sega Mega Drive games and Sonic CD.
  • This page is essentially part 2 of 2. This details how Solid Tiles and collision layers are used to create anything from simple slopes all the way to bigger Sonic set-pieces like loops. For part 1, describing what Solid Tiles are and how they are used directly, go to Solid Tiles.

Solid Terrain

Slopes and other floors within chunks are created by slotting Solid Tiles together like a jigsaw. There are enough variations of Solid Tiles available (and even more when they are flipped around) to construct many different varied slopes, whether they are smooth like halfpipes or more randomised like grass.

Chunks

Those slopes are constructed within chunks (a chunk being a 16 x 16 square of Solid Tiles in Sonic 1, 8 x 8 after), which in turn are also slotted together in a similar way to build terrain layouts.

Layers

Each Genesis Sonic game has some form of layer system in place. In order for the Player to pass in front of one side of a loop, then go all the way round and pass behind the other, there needs to be some sort of "layer switching".

Chunk Swapping Method

In Sonic 1, loop chunks are simply built different. When the Player enters the loop from the left, only the right side of it is solid. As the Player goes around the loop, the entire chunk will swap for another half way and sets the left side solid instead.

This is achieved by having 2 different chunks, and the game only allows for a couple of these special chunk types per zone.

Layer Switcher Method

In Sonic the Hedgehog 2 onwards, the system became a lot more advanced. Here each and every chunk has 2 separate Solid Tile layers. Here, we will call these "A" and "B". The Player can be on one of these layers at any given time.

Note: Neither A nor B represent "front" or "back", the priority for graphics is handled separately from solidity layers.

These layers can have completely different (or identical) Solid Tiles on them. The Player object knows what layer they are on, and can collide with one of these layers at a time. This is a far more flexible system and can be used for all sorts of crossing paths, including loops.

During gameplay, the Player's layer is changed via layer switchers.

Layer Switcher Setup

A layer switcher is an object which, when a threshold is crossed by the Player, switches their collision layer to a predetermined value.

SPGLayerSwitcher.gif

layer switchers can be vertical or horizontal, and can be of various sizes with one of the following radiuses

 32, 64, 128, 256

SPGLayerSwitcherHorizontal.gif

The threshold is a vertical or horizontal line that stretches to both ends of the switcher.

Either side of the threshold line has a variable which determines the collision layer it should switch the Player to if they cross over to that side. The top or left layer we will call "layer_1", and the right or bottom layer we will call "layer_2".

Note: In the images/animations on this page, either side of a switcher will show both the layer and the visual priority it will set the Player to on the respective side of the threshold. Additionally, the Player's current layer and priority will be shown above them.

Grounded Only Flag

A layer switcher can be flagged as being only active while the Player is on the ground, which we will label as grounded_only switchers. These are typically used in the tops of loops.

Current Side Flag

SPGLayerSwitcherCurrentSide.gif

At any given time, no matter where the Player is, a layer switcher has a variable which we will call current_side that remembers what side of it the Player is currently on (either to the left / right or above / below).

Note: current_side is updated after the layer switching is checked/performed.

Visual Priority Flags

Separate to the collision layers, Switchers are also used to change the Player's visual priority (aka their sprite depth). This is either "H" or "L" ("High" or "Low"), and will determine if the Player is displayed in front or behind certain foreground elements.

Either side of the threshold line has a variable which determines the priority layer it should switch the Player to if they cross over to that side. The top or left priority we will call "priority_1", and the right or bottom priority we will call "priority_2".

Some switchers can also only set the priority, and completely ignore setting the collision layers. We will label these as priority_only switchers.

This is a completely separate system to the collision layers, so High or Low priorities don't need to correspond to A or B layers.

Layer Switcher Functionality

A layer switcher will only switch the Player's collision layer if they are within range. The range being the radius mentioned above. For a vertical switcher, the Player's Y Position has to be within the range

switcher's Y Position - switcher's Y Radius to switcher's Y Position + switcher's Y Radius

For a horizontal switcher, the Player's X Position has to be within the range

switcher's X Position - switcher's X Radius to switcher's X Position + switcher's X Radius

If that condition is met, it will then check if the Player has crossed the threshold.

Note: We will use the example of a vertical switcher here, but a horizontal switcher works exactly the same in the other axis.

If current_side is the left:

If the Player's X Position is less than switcher's X Position, the Player is still on the left, has not crossed the threshold and nothing will happen.
If the Player's X Position is greater than or equal to the switcher's X Position, the Player has crossed the threshold, it will trigger and their layer will be switched to layer_2 (same happens for the priority).


If current_side is the right:

If the Player's X Position is greater than or equal to switcher's X Position, the Player is still on the right, has not crossed the threshold and nothing will happen.
If the Player's X Position is less than the switcher's X Position, the player has crossed the threshold, it will trigger and their layer will be switched to layer_1 (same happens for the priority).


After these checks (whether it triggered a switch or not), the switcher will then update current_side based on what side the Player is now on.

Result

The result of this system is that the Player's layer is only switched when the switcher threshold is crossed. It works no matter how fast the Player is moving.

Additionally, because current_side is always updated even when the Player is outside of the switcher range, if the Player jumps over (or otherwise moves around) a switcher it won't trigger, even when they enter back into the range on the other side.


Loops

In Sonic 2 onwards, loops will use 2 or more layer switchers in order to swap the Player to the correct path.

SPGLayerSwitcherLoop.gif

Typically this is one grounded_only switcher in the middle of the loop, and one switcher after the loop. There isn't usually one before the loop as the game assumes the Player has already been set to the correct layer sometime beforehand (though it would be safest to put one before too).

Overlapping Paths

Waves

The 2 crossing waves in Chemical Plant are more simple than they look. Each path of the wave is a separate collision layer, and 2 switchers (one on top and one on the bottom) set the Player to the correct layer as they enter.

SPGLayerSwitcherWaves.gif

Along the wave at each peak or valley, priority_only switchers swap the Player's visual priority in order to weave the sprite in and out of the graphics, the entire time remaining the same single collision layer.

ZigZag Path

Sometimes a path ends in a spring, and sends you back where you came from but takes you on an entirely new path. This is achieved with layer switchers situated right next to the spring, ensuring you have to travel all the way along the zig zag path.

SPGLayerSwitcherZigZag.gif

Notes

  • On this guide and in it's images, layer labels [A, B] and priority labels [L, H] represent values [0, 1] respectively in the original games.
  • This page is essentially part 2 of 2. This details how Solid Tiles and collision layers are used to create anything from simple slopes all the way to bigger Sonic set-pieces like loops. For part 1, describing what Solid Tiles are and how they are used directly, go to Solid Tiles.