don't click here

Collision format

Discussion in 'Engineering & Reverse Engineering' started by JoseTB, Aug 20, 2004.

  1. JoseTB

    JoseTB

    Tech Member
    716
    59
    28
    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.

    [​IMG]

    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:

    [​IMG]

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

    [​IMG]

    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

    [​IMG]

    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:

    [​IMG]

    And it creates an inverted column:

    [​IMG]

    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:

    [​IMG]

    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:

    [​IMG]


    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.

    Comments,questions,suggestions or whatever are welcome.

    (updated with slope info,as LOst points)
     
  2. LOst

    LOst

    Tech Member
    4,891
    8
    18
    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.
     
  3. JoseTB

    JoseTB

    Tech Member
    716
    59
    28
    That was a mistake by my part.Now is updated with slope data info.Thanks for point the error.
     
  4. Icy Guy

    Icy Guy

    Hedgehog. Sonic the Hedgehog. Member
    776
    0
    0
    California
    GoldenEye 007 level hack
    [​IMG]

    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).
     
  5. JoseTB

    JoseTB

    Tech Member
    716
    59
    28
    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.
     
  6. Dr. Ivo

    Dr. Ivo

    Professional Reverse Engineer Tech Member
    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.)
     
  7. LOst

    LOst

    Tech Member
    4,891
    8
    18
    And Dr. Ivo enters the room, and Sonic is complete!
     
  8. Hivebrain

    Hivebrain

    Administrator
    3,048
    160
    43
    53.4N, 1.5W
    Github
    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.
     
  9. Dr. Ivo

    Dr. Ivo

    Professional Reverse Engineer Tech Member
    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.
     
  10. Hivebrain

    Hivebrain

    Administrator
    3,048
    160
    43
    53.4N, 1.5W
    Github
    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.
     
  11. Lostgame

    Lostgame

    producer/turnablist. homebrew dev. cosplayer. Oldbie
    4,134
    58
    28
    Toronto, ON
    The O.I.C.
    Thanks. Maybe I can figure collision arrays out for Crackers and add it to my guide...