Actions

Difference between revisions of "SPG:Rebound"

From Sonic Retro

(Accurate boss rebound (added absent info))
(New formatting)
Line 4: Line 4:
  
 
==Badniks==
 
==Badniks==
 +
When the Player destroys a Badnik, and they are in the air, the game checks to see if they should rebound or not.
  
When Sonic destroys a badnik, and he is in the air, the engine checks to see if he should rebound or not.
+
If the Player's '''''Y Position''''' is greater than that of the Badnik, or their '''''Y Speed''''' is negative, they will not rebound. Instead, <code>sign(Y Speed)</code> will be subtracted from '''''Y Speed''''' (this is not limited to ''0''. If '''''Y Speed''''' were ''0.25 (64 subpixels)'', it would not be set to ''0'', but to ''-0.75 (-192 subpixels)''). This slight reduction of vertical speed helps give the impression that the Badnik had some weight to it.
  
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 the Player's '''''Y Position''''' is less than that of the Badnik and their '''''Y Speed''''' is positive, they will rebound. Their '''''Y Speed''''' will simply be multiplied by ''-1'', reversing it fully.
  
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. His Y speed will simply be multiplied by -1.  
+
Note: '''''X Speed''''' is totally unaffected by destroying a Badnik, both in the air and when rolling on the ground.
  
But can't you control the bounce by holding or not holding the jump button? Well yes, but that is actually part of the main jumping code.
 
  
If Sonic has jumped (and only if he has jumped) into the badnik, the variable jump height code is still in effect. As mentioned in the Jumping section of this guide - during a jump, at any point if the player isn't holding jump and his Y speed is less than -4, it will be set to -4. For this reason, if you are not holding jump when you collide with the enemy, and if your new Y speed is less than -4, it will be set to -4 because the jump code does that already. Effectively, allowing you to control the rebound height.
+
==Bounce Height==
 +
But can't you control the height of the bounce by holding or not holding the jump button? Well yes, but that is actually part of the main jumping code.
 +
 
 +
If the Player has jumped (and only if they has jumped) into the Badnik, the variable jump height code is still in effect. As mentioned in the [[SPG:Jumping#Variable_Jump_Height|Variable Jump Height]] - during a jump, at any point if the player isn't holding jump and their '''''Y Speed''''' is less than ''-4'', it will be set to ''-4''. For this reason, if you are not holding jump when you collide with the enemy, and if their new '''''Y Speed''''' is less than ''-4'', it will be set to ''-4'' because the jump code does that already. Effectively, allowing you to control the rebound height.
 +
 
 +
This means that if you weren't jumping, and instead land on a Badnik by rolling, you cannot control your bounce height at all, as the jump height code is not in effect.
 +
 
 +
Note:
 +
* This bounce control scenario applies to all other similar rebounds, such as from Item Monitors.
  
NOTE: X speed is totally unaffected by destroying a badnik, both in the air and when rolling on the ground.
 
  
 
==Monitors==
 
==Monitors==
 +
Note: For more details about collision with Item Monitors, see [[SPG:Solid_Objects#Item_Monitor|Solid Objects]] and [[SPG:Game_Objects#Item_Monitors|Game Objects]].
  
 
===Sonic 1 Method===
 
===Sonic 1 Method===
 
 
(used in [[Sonic 1]], [[Sonic 2]], [[Sonic CD]], and [[Sonic 3]])
 
(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.
+
When the Player, spinning, collides with a monitor while in the air, the game checks whether their '''''Y Speed''''' is positive or not. If it is, they will rebound off of the Item Monitor in the same way as they do Badniks - only without bothering to compare their '''''Y Position''''' to that of the Monitor. The Player 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.)
+
However, if their '''''Y Speed''''' is negative upon collision with the Monitor, it then compares the Player's '''''Y Position''''' with that of the Monitor. If the Player's '''''Y Position''''' is less, then they are moved outside of the Monitor to the side, as if it were solid, and it is not destroyed. If the Player's '''''Y Position''''' is greater, then the Player bumps into the bottom of the Monitor, bouncing it upward a little bit (for example, if the monitor is in a tree this knocks it down.)
  
 
===Sonic & Knuckles Method===
 
===Sonic & Knuckles Method===
 +
(used in [[Sonic & Knuckles]] and [[Sonic 3 & Knuckles]])
  
(used in [[Sonic & Knuckles]] and [[Sonic 3 & Knuckles]])
+
In Sonic & Knuckles, the Item Monitor collision behaviour has been revised. Monitors are not considered solid when the Player hits them while their '''''Y Speed''''' is negative, and they 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.
  
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 their '''''Y Speed''''' is positive when they hits the Monitor, they will rebound normally as they do in the other games. But if '''''Y Speed''''' is negative, their '''''Y Speed''''' will be multiplied by ''-1''. This means if they jumps into a Monitor from underneath, they'll be bounced downward. Also, if they hit a Monitor in its corner as they jump over it, they'll be bounced back toward the ground.
  
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.
  
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==
 
==Bosses==
 +
When the Player hits a boss while in the air, their '''''X Speed''''' and '''''Y Speed''''' are both divided by ''2'' and reversed (so, multiplied by ''-0.5'').
 +
Though, if on the ground, their '''''Ground Speed''''' is not affected at all. In your game, you may wish to fix that and have '''''Ground Speed''''' reverse and divide by ''2''.
  
When the Player hits a boss while in the air, their X Speed and Y Speed are both divided by 2 and reversed (so, multiplied by -0.5).
+
If they are rebounded by a boss upward by this, then the standard jump circumstances still 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.
Though, if on the ground, their Ground Speed is not affected at all. In your engine, you may wish to fix that and have Ground Speed reverse and divide by 2.
 
  
If they are rebounded by a boss upward by this, then the standard jump circumstances still 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.
 
  
 
==Notes==
 
==Notes==
 
+
* Gravity is added to '''''Y Speed''''' before the engine checks for and/or performs the rebounding routine.
Gravity is added to Y speed before the engine checks for and/or performs the rebounding routine.
 
  
 
[[Category:Sonic Physics Guide|Rebound]]
 
[[Category:Sonic Physics Guide|Rebound]]

Revision as of 04:57, 18 June 2023

Sonic Physics Guide
Collision
Physics
Gameplay
Presentation
Special

Notes:

Badniks

When the Player destroys a Badnik, and they are in the air, the game checks to see if they should rebound or not.

If the Player's Y Position is greater than that of the Badnik, or their Y Speed is negative, they will not rebound. Instead, sign(Y Speed) will be subtracted from Y Speed (this is not limited to 0. If Y Speed were 0.25 (64 subpixels), it would not be set to 0, but to -0.75 (-192 subpixels)). This slight reduction of vertical speed helps give the impression that the Badnik had some weight to it.

On the other hand, if the Player's Y Position is less than that of the Badnik and their Y Speed is positive, they will rebound. Their Y Speed will simply be multiplied by -1, reversing it fully.

Note: X Speed is totally unaffected by destroying a Badnik, both in the air and when rolling on the ground.


Bounce Height

But can't you control the height of the bounce by holding or not holding the jump button? Well yes, but that is actually part of the main jumping code.

If the Player has jumped (and only if they has jumped) into the Badnik, the variable jump height code is still in effect. As mentioned in the Variable Jump Height - during a jump, at any point if the player isn't holding jump and their Y Speed is less than -4, it will be set to -4. For this reason, if you are not holding jump when you collide with the enemy, and if their new Y Speed is less than -4, it will be set to -4 because the jump code does that already. Effectively, allowing you to control the rebound height.

This means that if you weren't jumping, and instead land on a Badnik by rolling, you cannot control your bounce height at all, as the jump height code is not in effect.

Note:

  • This bounce control scenario applies to all other similar rebounds, such as from Item Monitors.


Monitors

Note: For more details about collision with Item Monitors, see Solid Objects and Game Objects.

Sonic 1 Method

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

When the Player, spinning, collides with a monitor while in the air, the game checks whether their Y Speed is positive or not. If it is, they will rebound off of the Item Monitor in the same way as they do Badniks - only without bothering to compare their Y Position to that of the Monitor. The Player will rebound upward every time, no matter what.

However, if their Y Speed is negative upon collision with the Monitor, it then compares the Player's Y Position with that of the Monitor. If the Player's Y Position is less, then they are moved outside of the Monitor to the side, as if it were solid, and it is not destroyed. If the Player's Y Position is greater, then the Player bumps into the bottom of the Monitor, bouncing it upward a little bit (for example, 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 Item Monitor collision behaviour has been revised. Monitors are not considered solid when the Player hits them while their Y Speed is negative, and they 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.

If their Y Speed is positive when they hits the Monitor, they will rebound normally as they do in the other games. But if Y Speed is negative, their Y Speed will be multiplied by -1. This means if they jumps into a Monitor from underneath, they'll be bounced downward. Also, if they hit a Monitor in its corner as they jump over it, they'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 the Player hits a boss while in the air, their X Speed and Y Speed are both divided by 2 and reversed (so, multiplied by -0.5). Though, if on the ground, their Ground Speed is not affected at all. In your game, you may wish to fix that and have Ground Speed reverse and divide by 2.

If they are rebounded by a boss upward by this, then the standard jump circumstances still 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.


Notes

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