Actions

SPG:Solid Objects

From Sonic Retro

Revision as of 19:13, 4 August 2020 by Lapper2 (talk | contribs) (Specific focus on how Sonic interacts with objects and vice versa, while 'Game Objects' page can focus on specific object behaviour, variables, and setup.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Notes: Research applies to all four of the Mega Drive games, and Sonic CD. If there are any varying differences between the games, this will be covered below.

Variables

The following variables/constants will be referenced frequently in this section.

//Variables
xpos: The X-coordinate of Sonic's center.
ypos: The Y-coordinate of Sonic's center.
xsp: The speed at which Sonic is moving horizontally.
ysp: The speed at which Sonic is moving vertically.
gsp: The speed at which Sonic is moving on the ground.
slope: The current slope factor (slp) value being used.
ang: Sonic's angle on the ground.
	
//Constants
acc: 0.046875
dec: 0.5
frc: 0.046875 (same as acc)
top: 6
jmp: 6.5 (6 for Knuckles)
slp: 0.125
slprollup: 0.078125
slprolldown: 0.3125
fall: 2.5

Introduction

There are many objects in Sonic games and they interact with Sonic in many different ways and are a very different beast than Solid Tiles. Object-player collision doesn't work the same way as Solid Tiles. This guide will go over the collision of various objects found in the Sonic trilogy.

Setup

Hitboxes and Solid Boxes (well, any object boxes) are built using a radius for width and a radius for height. However, just like with Sonic's sensors, this also includes the objects origin.

SPGHitBoxRadius.png

So, frustratingly, a hitbox with a width radius of 8 (when defined as 8 in the code) ends up being 17 pixels wide in-game rather than 16. As a result, all hitboxes in the entire game will be an odd number in size.

Sonic's Sizes

At any given time Sonic has 3 size radius's. Firstly, his Push Radius which always remains constant (for pushing walls). He also has his Body Width Radius and his Body Height Radius (for floor/ceiling collision) both of which will change depending on Sonic's state.

Note: Information on these and how they change can be found at Solid Tiles. For specific object hitbox sizes, see Game Objects.

Object Hitboxes

Objects such as rings, enemies, and bumpers have a hitbox, which is a general area that will trigger some kind of reaction with Sonic when both their hitboxes overlap. Object hitboxes are centered on the object's x and y positions.

There are various types of hitboxes that objects use: Ones for collectables like rings, ones for Badniks, ones which always hurt Sonic, and special ones that use object-specific responses. They all do different things, however, the method they use to come into contact with Sonic in the first place is all the same.

Sometimes objects which seem solid (like bosses or bumpers) actually only have a hitbox, and when they overlap, simply push Sonic in the other direction. As a general rule, any seemingly solid object that Sonic cannot stand on is most likely actually using a hitbox rather than real solidity.

Sonic's Hitbox

In order to interact with other object's hitboxes, Sonic needs his own.

SPGHitBoxes.png

Sonic's hitbox is much like any object's. It sits at Sonic's xpos and ypos. It has a width radius of 8, and its height radius is always 3 pixels shorter than Sonic's Body Height Radius.

When crouching, Sonic's hitbox needs to shrink. Problem is, Sonic's position and height radius don't actually change at all while crouching. So to tackle this it manually updates the hitbox's size and position while Sonic crouches, where 12px is added to the hitbox's y position, and the hitbox's height radius is set to 10.

Solid Objects

Note: This section is a work in progress. While the information here is accurate, it may not paint the entire picture at this time.

As stated above, object collision is totally separate from tile collision. Sonic does not collide with objects using his solid tile sensors, instead, special calculations are used to check if Sonic's general shape is inside an object's solid box, and push him out.

General Solid Object Collision

Usually, objects which want to be solid define a width radius and height radius for their solidity area, in much the same way as objects.

Though, Sonic's collision with these boxes does not involve his hitbox at all. Rather the game calculates a box the size of Sonic's sensor arrangement to be used.

To check for an overlap horizontally, the object combines its radius with Sonic's Push Radius, and if the absolute distance between Sonic's xpos and the object's x position is less than this combined radius then an overlap has occured.

To check the vertical overlap, it is much the same, though it will account for what Body Height Radius Sonic currently has, as it changes often.

If Sonic is found to be touching the object, the game will then decide whether he is to be popped out the top or bottom or the left or right of the object. The game will compare Sonic's position to the object's position to determine which side he is on. If Sonic is on the left for example and the game has decided he needs to be popped out to the object's left side, it will only do so if Sonic is moving right, towards the object. The same (but flipped) is true for colliding with the right.

If the game decides Sonic is to be popped out upwards, then Sonic will land on the object and the game will set a flag making him stick to the object's surface and stay grounded, even though he's not touching any Solid Tiles. This flag will remain true until Sonic walks off the object or jumps.

Object Specific Collision

While a general description of Solid Object collision may cover a pushable block or a solid rock, not all objects behave the same. Some objects have slopes, and some will change what kind of solidity they have to suit different situations.

Item Monitor

Item Monitors, as you may have noticed, are not always solid. While you can stand on them you can also go right through them while jumping or rolling. The game is actually checking what Sonic is doing and changing how the Item Monitor will react.

While not curled up in a ball, the Item Monitor acts as solid. The Item Monitor's hitbox isn't accessible at this time.

While curled, however, the item box will no longer have any solidity at all, and its hitbox is active and accessible. The hitbox collision is what destroys the Item Box and bounces Sonic off (Details in Monitors Rebound).

However, there is an exception. If Sonic is moving up (ysp < 0) while curled, the Item Box will in fact act solid. Additionally, if Sonic's ypos-16 is smaller than the item box's y position, the item box will bounce up with a speed of -1.5 knocking the Item Box upwards, and Sonic's ysp will be reversed.