Actions

Difference between revisions of "SPG:Solid Objects"

From Sonic Retro

m (Adding missing information from migration)
(Adding information.)
Line 38: Line 38:
  
 
====Sonic's Sizes====
 
====Sonic's Sizes====
At any given time Sonic has 3 size radius's.  
+
At any given time Sonic has 3 size radiuses.  
 
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.
 
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.
  
Line 86: Line 86:
 
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.
 
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.
  
 +
====Checking for an overlap====
 
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 occurred.
 
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 occurred.
  
Line 97: Line 98:
  
 
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.
 
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.
 +
 +
===Pushable Blocks===
 +
 +
Pushable blocks (specifically the type found in Marble Zone) are mostly normal solid objects, except for the fact when you are pushing them they will move themselves and Sonic 1 pixel in the push direction.
 +
However, they clearly do not move this fast... Well, for some reason the block will only move around every 3 frames for so, but it's not consistent and may not be 100% intentional.
  
 
===Item Monitor===
 
===Item Monitor===
Line 106: Line 112:
 
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 [[SPG:Rebound#Monitors|Monitors Rebound]]).
 
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 [[SPG:Rebound#Monitors|Monitors Rebound]]).
  
However, if Sonic is moving up (''ysp'' < 0) while curled, the box will act solid. Aditionally, 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 and Sonic's ''ysp'' will be reversed, knocking the Item Box upwards.  
+
However, there is an exception. If Sonic is moving up (''ysp'' < 0) while curled, the Item Box will in fact still 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 Y speed of -1.5 knocking the Item Box upwards, and Sonic's ''ysp'' will be reversed.
  
 
[[Category:Sonic Physics Guide|Solid Objects]]
 
[[Category:Sonic Physics Guide|Solid Objects]]

Revision as of 10:32, 5 August 2020

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 radiuses. 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.

Quirks With Hitboxes

Because these hitboxes aren't even numbered in size, and because object origins don't lay perfectly centred between pixels (rather they are 1px left and down) most hitboxes will also appear 1px too big on the right side and the bottom side. This is simply how things work in game and for that reason won't be ignored. Sprites like rings are even numbered sizes (such as 16 x 16) so an anomaly like the following can (and does, always) occur.

SPGRingTest.gif

Rings can be collected from one direction sooner than the other, you can try it yourself via debug mode. As long as the sprite of the ring is 4px out from the tiles on each side, you'll experience this inconsistency. A Ring's hitbox is defined as a radius of 6, but this results in a box with a width of 13 rather than 12. Because all sprites like this are an even size, but their hitbox must be odd, the box cannot be perfectly set on the sprite and will be larger to the left and bottom.

This is the case with any object's hitboxes.

The same is true for solid object boxes, so Sonic will push against objects 1px further away when facing leftwards than he will tiles.

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.

Checking for an overlap

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 occurred.

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.

Pushable Blocks

Pushable blocks (specifically the type found in Marble Zone) are mostly normal solid objects, except for the fact when you are pushing them they will move themselves and Sonic 1 pixel in the push direction. However, they clearly do not move this fast... Well, for some reason the block will only move around every 3 frames for so, but it's not consistent and may not be 100% intentional.

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 still 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 Y speed of -1.5 knocking the Item Box upwards, and Sonic's ysp will be reversed.