Actions

SPG:Camera

From Sonic Retro

Note: Applies to Sonic 1, 2, 3 & K, and CD except where otherwise noted.

View Borders

Visual representation of the borders in the camera. White is the borders, Green is the Y position in the view that Sonic stays at when on the ground.

The Sonic games have a screen size of 320x224 pixels during normal Zone play. Sonic isn't always locked in the centre of the screen, but has some freedom of movement within the view borders before it begins to scroll.

Horizontal Border

  • Left border: 144
  • Right border: 160

If you exceed the border, the camera will move by how much you've exceeded, up to 16. So if Sonic moves faster than this, the camera will lag behind.

I'm actually not sure why the developers made the view off-centre like this. It makes it harder to see where you're going when moving left rather than right. If you so choose, you can change the borders to 152 and 168 instead, to even things out a bit.

Sonic CD, though, effectively has both borders set to 160 so that Sonic is always at dead centre and the view scrolls immediately when he begins moving.

Vertical Border

In the Air

  • Top border: 64
  • Bottom border: 128

If you exceed the border, the camera will move by how much you've exceeded, up to 16. So if Sonic moves faster than this, the camera will lag behind.

Note: Knuckles uses the same vertical borders while gliding and climbing. He's considered back on the ground when he starts to clamber over the corner of a wall, or stands up after sliding from a glide (i.e. when sliding, even though he is in contact with the ground, it still considers him to be in the air).

On the Ground

If Sonic's Y is not equal to 96, the camera will move by the difference, up to 6 (if Sonic's Y speed is less than or equal to 6), or 16 (if Sonic's Y speed is more than 6). This makes the camera catch up slowly right after landing, but otherwise stay centred.

Looking Up and Down

  • Looking Up: Scrolls up by 104 pixels, at a rate of 2 per step.
  • Looking Down: Scrolls down by 88 pixels, at a rate of 2 per step.

In Sonic 1, the camera begins to scroll immediately when you press up or down. Obviously, this is annoying if there is to be a spindash or super peel out in your engine. In Sonic 2, 3 & K, the solution is to simply wait 120 steps after you begin to hold the button before it starts scrolling. In Sonic CD, though, another (IMO inferior) method is employed. After you press the up or down button, you have 16 steps to press it again, upon which the screen begins to scroll. The lame thing about this is that it will freeze the scrolling if you press the up or down button while the screen is already scrolling. For instance, look up by double-tapping, let go, and then press down. The screen will freeze, and stay there until you let go. Even initiating a spindash doesn't return things to normal.

In all the games, once you let go of up or down (also in Sonic 2, 3, & K, once you initiate a spindash), the camera scrolls back to the neutral position by 2 pixels per step.

Spindash Lag

(Not in Sonic CD)

Sonic has a previous position table in memory. The game knows where he's been over the last several seconds with great precision. This is called upon for the spindash lag.

When the spindash is launched, a timer (t) is set to 32 (minus the rev variable, which can be between 0 and 8 - see spindash for more details). t then decreases by 1 every step.

While t is non-zero, the camera stops behaving normally and begins to move, not based on Sonic's current position, but his position t-1 steps ago. Once t runs out, the camera returns to business as usual.

If you think about it, though, if the camera travels 32 steps into the past, and moves based on those recorded positions for a duration of 32 steps, it would effectively just repeat them, and then switch back to the current position, hopping 32 steps back into the future. This isn't how it works. Since it goes back 32 steps, and waits 32 more to return to normal, that means a total of 64 recorded camera positions. In order to take all of these positions into account during the 32 steps before the camera returns to normal, they are added together in pairs.

As an example, let's imagine Sonic has been charging up his spindash for at least 32 steps, so that he hasn't moved during this time. Then, he launches at a speed of 8. Since in the last 32 steps he hasn't moved, the camera will move by 0 + 0 for 16 frames, remaining stationary. Then, it will have caught up to the point in time at which Sonic launched. Sonic will have been moving 8 pixels every step from this point on. The camera will then move 16 pixels for 16 more steps until t runs out. (Technically, Sonic doesn't move in the exact frame in which the spindash launches, so the camera will move by 0 + 8 for one step, and then 8 + 8 for a while, and the 7 + 8 as friction kicks in, and then 7 + 7, and so on).

The trouble with this lag is that if you initiate and release a spindash quickly enough after moving, the camera will actually move backward to follow where you've been.

Flame Shield/Hyper Sonic Air Dash

The same lag routine happens when Sonic does the airdash as Hyper Sonic, or with the Flame Shield. However, the trick is when he launches, the entire previous position table is blanked out with his current position, so that the camera can't scroll backward. In your engine, if you do the same thing for the launch of a spindash, you won't have to worry about backward scrolling at all.

Notes

You can achieve an almost identical effect without a previous position table by simply disallowing the camera to move for about 16 steps after launching. This is somewhat easier to do.

I actually don't care for the spindash/airdash lag all that much. You can live without it, as Sonic CD shows, and it can cause some pretty ugly camera movements when you spindash into a wall, or worse a red spring. You might consider leaving it out of your engine altogether.

Extended Camera (Sonic CD)

In Sonic CD only, when Sonic reaches an X speed of 6 (or is 16 steps into charging up a spindash or super peel out), the camera's X position begins to shift forward. It moves 64 pixels in total, 2 per step. When his X speed drops back below 6, it moves back. For some reason, it doesn't bother to check his X speed in order to activate or deactivate this shift while he is in the air, though. This can lead to an off-centre view. If you use this shift effect in your engine, I suggest doing the check while airborne as well.