Wednesday, June 21, 2017

The collision change object

The mechanism responsible for changing which collision patterns are currently active is the collision change object. It is more commonly known as the "path swapper" object, and it is labelled Obj_PathSwap in the current disassembly, but it was called "colichg" in the original source code, so I'm gonna go with that.
Obj_PathSwap:
    move.l  #Map_PathSwap,$C(a0)
    move.w  #$26BC,$A(a0)
    ori.b   #4,4(a0)
    move.b  #$40,7(a0)
    move.b  #$40,6(a0)
    move.w  #$280,8(a0)
    ...
Though normally invisible, this object appears as a line of four rings when debug is enabled: in Sonic 3 & Knuckles, the player must be in object placement mode, whereas in standalone Sonic 3 just having the cheat on will suffice.


The placement of the ring sprites gives away the object's length and its orientation. These are set through the object's subtype: bits 0 and 1 define the length, from the possible values of 32, 64, 128 or 256 pixels long. The longest variant is rarely used, however, and it's even harder to track down because it actually uses the same sprite mappings as the second longest for some reason.

Meanwhile, bit 2 sets the object's orientation: vertical if the bit is clear, and horizontal if the bit is set.


The object's behavior is decidedly simple: if the player crosses over the object within the span of its length, their current collision path, as well as their sprites' priority, will change to whatever the object says it should. This is controlled by the next four bits in the subtype, as follows:

  • Bit 3 is the collision path chosen when the player crosses over to the right of the object, or below when the object is horizontal.
  • Bit 4 is the collision path chosen when the player crosses over to the left of the object, or above when the object is horizontal.
  • Bit 5 is the sprite priority chosen when the player crosses over to the right of the object, or below when the object is horizontal.
  • Bit 6 is the sprite priority chosen when the player crosses over to the left of the object, or above when the object is horizontal.

Finally, if bit 7 is set, the object will only take action if the player was on the ground when they crossed it. This behavior is what prevents you from being able to change which path you're on by simply jumping around inside loops: since the collision change object is only touching the top of the loop and you need to be on the ground to activate it, the only way it can possibly happen is if you're running along the ceiling of the loop when you cross it.

1 comment:

  1. It's quite likely that this is a dumb question, but would you mind explaining how the "double" loops in Sandopolis work?

    ReplyDelete