Actions

SPG:Rebound

From Sonic Retro

Badniks

When Sonic destroys a badnik, and he is in the air, the engine checks to see if he should rebound or not.

If Sonic's Y position is greater than that of the badnik, or his Y speed is negative, he will not rebound. Instead, 1 times the sign of Y speed will be subtracted from Y speed (this is not limited to 0 - if Y speed were .25, it would not be set to 0, but to -.75). This slight attenuation of his speed helps give the impression that the badnik had some weight to it.

On the other hand, if Sonic's Y position is less than that of the badnik and his Y speed is positive, he will rebound. If the player is holding down the Jump button at the time (or Sonic is falling from having rolled off a ledge, and not from having jumped), his Y speed will simply be multiplied by -1. Otherwise, his Y speed will be set to whichever is greater: -1, or Y speed times -1. (Remember, -3 is "greater" than -4, because we're talking about negative numbers.)

Once Sonic has rebounded - if and only if he has jumped, and not fallen from rolling off of a ledge - he behaves like any normal jump: releasing the Jump button while Y speed is less than -4 will set Y speed to -4, air drag is calculated, and so on.

NOTE: X speed is totally unaffected by destroying a badnik, both in the air and when rolling on the ground.

Monitors

Sonic 1 Method

(used in Sonic 1, Sonic 2, Sonic CD, and Sonic 3)

When Sonic, spinning, collides with a monitor while in the air, the engine checks whether his Y speed is positive or not. If it is, he will rebound off of the monitor in the same way as he does badniks - only without bothering to compare his Y position to that of the monitor. Sonic will rebound upward every time, no matter what.

However, if his Y speed is negative upon collision with the monitor, it then compares Sonic's Y position with that of the monitor. If Sonic's Y position is less, then he is moved outside of the monitor to the side, as if it were solid, and it is not destroyed. If Sonic's Y position is greater, then Sonic bumps into the bottom of the monitor, bouncing it upward a little bit (if the monitor is in a tree, this knocks it down.)

Sonic & Knuckles Method

(used in Sonic & Knuckles and Sonic 3 & Knuckles)

In Sonic & Knuckles, the monitor collision behaviour has been revised. Monitors are not considered solid when Sonic hits them while his Y speed is negative, and he can't bounce them up by hitting them from beneath. This means the Flame Shield Monitor in the tree in Angel Island Act 2 can't be knocked down when Sonic 3 is locked on to Sonic & Knuckles, even though it can be in Sonic 3 alone. Why this change was made is beyond me.

If his Y speed is positive when he hits one, he will rebound normally as he does in the other games. But if his Y speed is negative, his Y speed will be multiplied by -1. This means if he jumps into a monitor from underneath, he'll be bounced downward. Also, if he hits a monitor in its corner as he jumps over it, he'll be bounced back toward the ground.

NOTE: In all the games, X speed is totally unaffected by destroying a monitor, both in the air and when rolling on the ground.

Bosses

When Sonic hits a boss while in the air, Y speed and X speed are both reversed (multiplied by -1). If he is rebounded upward by this, then the standard circumstances apply: releasing the Jump button while Y speed is less than -4 will set Y speed to -4, air drag is calculated, and so on.

When Sonic hits a boss while on the ground, his speeds are not affected at all. In your engine, you may wish to fix that and have X speed reverse.

Notes

Gravity is added to Y speed before the engine checks for and/or performs the rebounding routine.