# Sonic and Sega Retro Message Board: Collision format - Sonic and Sega Retro Message Board

Page 1 of 1

## Collision format

### #1JoseTB  Posted 20 August 2004 - 12:35 PM

• Posts: 631
• Joined: 01-June 04
• Gender:Male
• Wiki edits:4
With this post,I'm going to explain how the collision format works.This post is more for new users,and nothing here is new,however I think that the actual info about about the collision isn't much specific,and I will explain here on my own way.Okay,let's start.

Each sonic game (s1/s2/s3/sk) have a "Main" collision data (usually called collision array) where all the collision blocks used in the game are.Then the collision data for each level just use the posible blocks in the collision array,but that's something that we'll see later.For now,let's look on the collision array.

First,you have to know that the collision blocks are directly applied to the 16x16 tiles of each zone,that mean that each collision block is always 16x16.

This is basically the table with represents a collision blocks.You probably have noticed that the system looks like x and y positions.Well,in fact is even more simple than that.Each block uses 16 (0F) bytes.There isn't any special format in the collision array.Is just the first 16 bytes the first collision block,the next 16 bytes the second,and so on.but let's look what that 16 bytes mean.

The X position in the table,is just the position of the actual byte.The value of that byte means the y position.It always create a column below the position.In the table,green numbers mean y value,and blue numbers mean the byte position (or x value)(for now,ignore the grey numbers) For example,if we have this:

00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00

That means will create a column in the second position with altitude of 3.This will be a representation of the position:

And because we said that it creates a column,the result in game will be this:

Also,as you can see,a value of 00 don't create a column.

Another example more complex:

04 05 05 06 06 07 08 08-09 0A 0A 0B 0C 0D 0D 0E

Red boxes mean that these are the actual value of each byte.

"Okay,and what about the grey numbers that we saw before?"

They work like Y positions,but instead of creating a "normal" column,it creates one "inverted"

For example:

00 00 00 FE 00 00 00 00 00 00 00 00 00 00 00 00

The position in the table is:

And it creates an inverted column:

That will create the collision,but you have to set to that block the slope effect.This is where the angle data comes.Each byte of this data correspond to one collision blocks.If the byte is the first,it will take effect on the first collision block in the array,if is the second,the second block,and it follow that.The format is simple,to represent the slope just create two imaginary lines.The first character of the byte is a point in the left line,and the second in the right line.If you create a line between these points,you will have a representation of the slope.Let's look an example:

Block collision number 04 of s1:

Now we go to the 4 byte on the angle data in s1 (see below).It says 90. 9 will be the first point and 0 the second.Here is a representation about that:

That's all about the collision block format.Now,how each level uses it?

Instead of use directly data like the collision array,each byte represent one block from the collision array,and is directly related to the 16x16 tile position.Is simple.If a byte is 00,it means that it will use the first block collision in the collision array (first 16 bytes) If is 01,it will use second,and it continues.And how the game know in what 16x16 tile use that? Again very simple.The position of the byte,is the position of the tile.I mean,if you use 00 in the first position of the collision data of a level,It will use the block collision 00 in the first 16x16 tile in the level.If is the second position,the second tile.And it continues like that.

Now some info that you maybe want:

Collision Arrays:

-Sonic 1 (us) :
Primary collision array: \$62A00
Secondary collision array: \$63A00
Angle/curve array: \$62900

-Sonic 2 :
Collision array : \$42E50
Angle/curve array: \$42D50
-Sonic 3 :
\$706A0*

-Sonic & Knuckles :
\$96100*

Collision Data :

-Sonic 1 (us) :
GHZ : \$64A00
LZ : \$64B9A
MZ : \$64C62
SLZ : \$64DF2
SYZ : \$64FE6
SBZ : \$651DA

-Sonic 2 (Note:Data compressed with Kozinski compression) :
EHZ and HTZ primary : \$44E50
EHZ and HTZ secondary : \$44F40
MTZ : \$45040
OOZ : \$45100
MCZ : \$45200
CNZ primary : \$452A0
CNZ secondary : \$45330
CPZ and DEZ primary : \$453C0
CPZ and DEZ secondary : \$454E0
ARZ primary : \$45610
ARZ secondary : \$45760
WFZ/SCZ primary : \$458C0
WFZ/SCZ secondary : \$459A0

*Note:S3 and SK collision array adress taken from Esrael Homepage.

(updated with slope info,as LOst points)
This post has been edited by JoseTheBest: 20 August 2004 - 07:16 PM

### #2LOst  Posted 20 August 2004 - 04:13 PM

• Posts: 4886
• Joined: 10-January 03
• Gender:Male
• Wiki edits:2
The height maps as explained above are not functional without the angle array. The angle array is telling where the height map is facing. Without it, the height maps are useless.

Also each zone has their own list of arrays for angles, which are loaded in top of the main angle array.

### #3JoseTB  Posted 20 August 2004 - 07:18 PM

• Posts: 631
• Joined: 01-June 04
• Gender:Male
• Wiki edits:4
That was a mistake by my part.Now is updated with slope data info.Thanks for point the error.

### #4Icy Guy  Posted 20 August 2004 - 07:37 PM

• Hedgehog. Sonic the Hedgehog.
• Posts: 777
• Joined: 23-November 03
• Gender:Male
• Location:California
• Project:GoldenEye 007 level hack
• Wiki edits:2

Wouldn't the green 0 be one space up, given that the "inverted" numbers appear to be the X number + F0?

I want to make it clear that I'm not criticizing your explanation of the format, but, rather, I'm just bringing something to your attention that I think looks like a little off (to me, that is; but, then again, I hardly know what the hell I'm talking about).

### #5JoseTB  Posted 20 August 2004 - 07:47 PM

• Posts: 631
• Joined: 01-June 04
• Gender:Male
• Wiki edits:4

Icy Guy, on Aug 20 2004, 07:37 PM, said:

Wouldn't the green 0 be one space up, given that the "inverted" numbers appear to be the X number + F0?

Actually,what it would be more correct is just remove it.But I just wanted to show that the value 00 exist,making the function of a "non-existant" block.The only posibles blocks are each square in the table.If the value is below or up that,it won't do anything.

### #6Dr. Ivo  Posted 07 October 2004 - 03:51 AM

• Professional Reverse Engineer
• Posts: 42
• Joined: 04-February 04
• Gender:Male
I very much admire the full out explanation with imagery.

However, your explanation of the angle assignments is wrong. It seems you got that information from Nemesis' site, and he is wrong as well.

The angle assignments have NOTHING to do with that graph.

They are simply representative of 360 logical degrees divided into 128 ticks, going around a circle in a counter clockwise direction, assigned in twos so that they translate directly to word-length table indexes. For instance...

00 = Flat ground
20 = 45 degrees, going upward right to left
40 = Left
60 = 45 degrees, going upward left to right
80 = Ceiling
A0 = 45 degrees, going downward left to right
C0 = Right
E0 = 45 degrees, going downward right to left

Get it?

Nice work, though. I always appreciate when people take the time to document the engine.

(I made this information public, four years ago (2000) and released the first ever collision block/angle viewer as a proof of concept. I gave the information to Stealth who perfected the algorithms for use in a future version of SonED. So, no more manual editing will be necessary in time.)
This post has been edited by Dr. Ivo: 07 October 2004 - 12:40 PM

### #7LOst  Posted 07 October 2004 - 03:54 AM

• Posts: 4886
• Joined: 10-January 03
• Gender:Male
• Wiki edits:2

Dr. Ivo, on Oct 7 2004, 11:51 AM, said:

I very much admire the full out explanation with imagery.

However, your explanation of the angle assignments is wrong. It seems you got that information from Nemesis' site, and he is wrong as well.

The angle assignments have NOTHING to do with that graph.

They are simply representative of 320 logical degrees divided into 128 ticks, going around a circle in a counter clockwise direction. For instance...

00 = Flat ground
20 = 45 degrees, going upward right to left
40 = Right wall
60 = 45 degrees, going upward left to right
80 = Ceiling
A0 = 45 degrees, going downward left to right
C0 = Left wall
E0 = 45 degrees, going downward right to left

Get it?

Nice work, though. I always appreciate when people take the time to document the engine.

And Dr. Ivo enters the room, and Sonic is complete!

### #8Hivebrain  Posted 07 October 2004 - 12:42 PM

• Posts: 2747
• Joined: 15-January 03
• Gender:Male
• Location:53.4N, 1.5W
• Project:HivePal 2.0
• Wiki edits:6,176
Someone should write a program that reads a collision array and outputs an angle array. I might try making one.

Does anyone know exactly what the second collision array is for? I seem to remember reading somewhere that it has something to do with rotated blocks.

### #9Dr. Ivo  Posted 08 October 2004 - 04:18 AM

• Professional Reverse Engineer
• Posts: 42
• Joined: 04-February 04
• Gender:Male
The second collision array is used by the FindWall function, wherein a routine needs "width" information about a block, rather than "height" information. For the game to work correctly, each block in the second array is a copy of the block of the same index in the first array, but rotated 90 degrees.

That's the other problem with this documentation. If you change a block in the first array, you should also change the block in the second array! It is not totally necessary, but could lead to some very unexpected results.
This post has been edited by Dr. Ivo: 08 October 2004 - 04:20 AM

### #10Hivebrain  Posted 12 October 2004 - 01:57 PM

• Posts: 2747
• Joined: 15-January 03
• Gender:Male
• Location:53.4N, 1.5W
• Project:HivePal 2.0
• Wiki edits:6,176
Can someone think of a formula for converting a block in the main collision array to the rotated array? I'm stumped.

I can convert collision blocks to angles with a bit of trigonometry.

I'm going to write a program to read the collision array and output a rotated array and angle map.

### #11Lostgame  Posted 19 October 2004 - 03:04 PM

• resident geek girl + record label manager
• Posts: 4026
• Joined: 02-December 03
• Gender:Female
• Location:Toronto, ON
• Project:The O.I.C.
• Wiki edits:2
Thanks. Maybe I can figure collision arrays out for Crackers and add it to my guide...

Page 1 of 1