Actions

Difference between revisions of "SPG:Rolling"

From Sonic Retro

(Fixed some inaccuracies I think)
(Making rolling more consistent with other pages, using ground speed instead of x speed.)
Line 3: Line 3:
 
Research applies to all four of the [[Sega Mega Drive]] games, and [[Sonic CD]].
 
Research applies to all four of the [[Sega Mega Drive]] games, and [[Sonic CD]].
  
The following only applies when [[Sonic]] is on flat, dry land with no special power-ups. Curves, water physics, [[Super Sonic]], and [[Speed Shoes]] will be covered in separate guides.
+
==Variables==
 +
 
 +
The following variables/constants will be referenced frequently in this section.
 +
   
 +
<nowiki>//Variables
 +
xsp: the speed in which sonic is moving horizontally
 +
ysp: the speed in which sonic is moving vertically
 +
gsp: the speed in which sonic is moving on the ground
 +
//Constants
 +
acc: 0.046875
 +
dec: 0.5
 +
frc: 0.046875 (same as acc)
 +
rollfrc: 0.0234375 (half of frc)
 +
rolldec: 0.125
 +
</nowiki>
 +
==Ground Speed Conversion==
 +
''gsp'' is used to calculate ''xsp'' and ''ysp'' when on the ground. This is further described in [[SPG:Solid_Tiles#The_Three_Speed_Variables|The Three Speed Variables]].
 +
 
 +
xsp = gsp*cos(angle);
 +
ysp = gsp*-sin(angle);
  
 
==Friction==
 
==Friction==
  
When Sonic rolls up by pressing {{down}} on the directional pad, he can no longer accelerate. No matter how hard or how long you press in the direction of his motion, he'll behave as if you weren't doing a thing. The only thing that happens in this case is friction, which is half of Sonic's regular friction (in Sonic 3K, Super Sonic's friction is hard-coded to always be half of the regular friction).
+
When Sonic rolls into a ball by pressing {{down}} on the directional pad, he can no longer accelerate. No matter how hard or how long you press in the direction of his motion, he'll behave as if you weren't doing a thing. The only thing that happens in this case is friction, which is ''rollfrc'', half Sonic's regular friction (in Sonic 3K, Super Sonic's roll friction is hard-coded to always be half of the regular friction).
  
 
==Deceleration==
 
==Deceleration==
  
However, Sonic ''can'' decelerate while rolling.  If you hold in the opposite direction of his motion, X speed will be slowed by 0.125.  Additionally, unlike normal walking, friction is still in effect while rolling, even if you press in a direction. So, in effect, while decelerating, X speed slows by 0.125+0.0234375, or 0.1484375, every step.
+
However, Sonic ''can'' decelerate while rolling.  If you hold in the opposite direction of his motion, ''gsp'' will be slowed by ''rolldec'' each frame.  Additionally, unlike normal walking, friction is still in effect while decelerating. So in effect, while decelerating, ''gsp'' slows by 0.125+0.0234375 (or 0.1484375) every step.
  
Strangely, the same deceleration anomaly happens while rolling as while running.  If absolute X speed is less than 0.1484375, when this value is subtracted, instead of just setting X speed to zero, X speed is set to .5 in the opposite direction.  Thus, bizarrely, Sonic can turn around while rolling, even though he can't accelerate! This is fixed in Sonic 3 and Knuckles, so apparently the programmers themselves found this undesirable.
+
Similar to the anomaly explained in [[SPG:Running#Deceleration|Running]], if absolute ''gsp'' is less than 0.1484375, when this value is subtracted, instead of just setting ''gsp'' to zero, ''gsp'' is set to 0.5 in the opposite direction.  Thus, bizarrely, Sonic can turn around while rolling, even though he can't accelerate!
  
 
==Top Speed==
 
==Top Speed==
  
Now, just because Sonic cannot roll faster on his own, doesn't mean that a nice hill wouldn't give him some momentum every now and then. These hills and slopes can be used to roll at a very high speed. Just as with running though, Sonic has a top speed cap when rolling as well, though this one is much higher than the former, reaching a top speed of 16 pixels per step. Unlike running however, Sonic cannot surpass this speed cap by any means. If his ''xsp'' reaches a point where it reaches 16, and tries to go higher, it will automatically be set to 16 instead. Notice how I said ''xsp'' instead of ''gsp'', that's right, it caps Sonic's global horizontal velocity, rather than his ground velocity. This can cause the angle he's moving at to be incorrect compared to the angle he's supposed to be moving. You can just cap the ''gsp'' instead, that is, if you want the cap at all.
+
Now, just because Sonic cannot roll faster on his own, doesn't mean that a nice hill wouldn't give him some momentum every now and then. Gaining speed on slopes is covered in [[SPG:Solid_Tiles#Moving_At_Angles|Moving At Angles]]. These hills and slopes can be used to roll at a very high speed. Just as with running though, Sonic has a top speed cap when rolling as well, though this one is much higher than the former, reaching a top speed of 16 pixels per step. Unlike running however, Sonic cannot surpass this speed cap by any means. If his ''xsp'' reaches a point where it reaches 16, and tries to go higher, it will automatically be set to 16 instead. Notice how I said ''xsp'' instead of ''gsp'', that's right, it caps Sonic's global horizontal velocity, rather than his ground velocity. This can cause the angle he's moving at to be incorrect compared to the angle he's supposed to be moving. You can just cap the ''gsp'' instead, that is, if you want the cap at all.
  
 
==Criteria==
 
==Criteria==
Line 25: Line 44:
 
In Sonic and Knuckles (and Sonic 3 and Knuckles), this value is increased to 1. This is because in said game, Sonic is allowed to duck while his speed is below 1, so he can perform moves such as the Spindash without needing to come to a full stop (very helpful since Sonic could get stuck weirdly sliding on slopes starting with Sonic 3).
 
In Sonic and Knuckles (and Sonic 3 and Knuckles), this value is increased to 1. This is because in said game, Sonic is allowed to duck while his speed is below 1, so he can perform moves such as the Spindash without needing to come to a full stop (very helpful since Sonic could get stuck weirdly sliding on slopes starting with Sonic 3).
  
Also in Sonic and Knuckles, probably as a way to combat the anomaly associated with turning around while rolling in the previous games, Sonic unrolls if absolute X speed falls below 0.5.
+
Also in Sonic and Knuckles, probably as a way to combat the anomaly associated with turning around while rolling in the previous games, Sonic unrolls if absolute ''gsp'' falls below 0.5.
  
 
==Rolling Jump==
 
==Rolling Jump==
  
In Sonic 1, 2, 3, and Knuckles, you can't control Sonic's trajectory through the air with the directional buttons if you jump while rolling. This makes it kind of hard to Spindash to gain speed, and then make a precise jump. Though, in Sonic 3 and in Sonic & Knuckles, you can regain control of the directional keys if you perform a [[Insta-Shield]], or any other jump ability.
+
In Sonic 1, 2, 3, and Knuckles, you can't control Sonic's trajectory through the air with the {{left}}{{right}} buttons if you jump while rolling. This makes it kind of hard to Spindash to gain speed, and then make a precise jump. Though, in Sonic 3 and in Sonic & Knuckles, you can regain control of the directional keys if you perform a [[Insta-Shield]], or any other jump ability.
  
 
However, in Sonic CD and Mania, you can control a jump made while rolling, as if it were a totally normal jump. This is probably more fair to the player.
 
However, in Sonic CD and Mania, you can control a jump made while rolling, as if it were a totally normal jump. This is probably more fair to the player.
  
 
[[Category:Sonic Physics Guide|Rolling]]
 
[[Category:Sonic Physics Guide|Rolling]]

Revision as of 16:25, 27 December 2019

Notes:

Research applies to all four of the Sega Mega Drive games, and Sonic CD.

Variables

The following variables/constants will be referenced frequently in this section.

//Variables
xsp: the speed in which sonic is moving horizontally
ysp: the speed in which sonic is moving vertically
gsp: the speed in which sonic is moving on the ground	
//Constants
acc: 0.046875
dec: 0.5
frc: 0.046875 (same as acc)
rollfrc: 0.0234375 (half of frc)
rolldec: 0.125

Ground Speed Conversion

gsp is used to calculate xsp and ysp when on the ground. This is further described in The Three Speed Variables.

xsp = gsp*cos(angle);
ysp = gsp*-sin(angle);

Friction

When Sonic rolls into a ball by pressing Down on the directional pad, he can no longer accelerate. No matter how hard or how long you press in the direction of his motion, he'll behave as if you weren't doing a thing. The only thing that happens in this case is friction, which is rollfrc, half Sonic's regular friction (in Sonic 3K, Super Sonic's roll friction is hard-coded to always be half of the regular friction).

Deceleration

However, Sonic can decelerate while rolling. If you hold in the opposite direction of his motion, gsp will be slowed by rolldec each frame. Additionally, unlike normal walking, friction is still in effect while decelerating. So in effect, while decelerating, gsp slows by 0.125+0.0234375 (or 0.1484375) every step.

Similar to the anomaly explained in Running, if absolute gsp is less than 0.1484375, when this value is subtracted, instead of just setting gsp to zero, gsp is set to 0.5 in the opposite direction. Thus, bizarrely, Sonic can turn around while rolling, even though he can't accelerate!

Top Speed

Now, just because Sonic cannot roll faster on his own, doesn't mean that a nice hill wouldn't give him some momentum every now and then. Gaining speed on slopes is covered in Moving At Angles. These hills and slopes can be used to roll at a very high speed. Just as with running though, Sonic has a top speed cap when rolling as well, though this one is much higher than the former, reaching a top speed of 16 pixels per step. Unlike running however, Sonic cannot surpass this speed cap by any means. If his xsp reaches a point where it reaches 16, and tries to go higher, it will automatically be set to 16 instead. Notice how I said xsp instead of gsp, that's right, it caps Sonic's global horizontal velocity, rather than his ground velocity. This can cause the angle he's moving at to be incorrect compared to the angle he's supposed to be moving. You can just cap the gsp instead, that is, if you want the cap at all.

Criteria

In Sonic 1, 2, and 3 Sonic can't roll up unless his absolute X speed is greater than or equal to 0.5.

In Sonic and Knuckles (and Sonic 3 and Knuckles), this value is increased to 1. This is because in said game, Sonic is allowed to duck while his speed is below 1, so he can perform moves such as the Spindash without needing to come to a full stop (very helpful since Sonic could get stuck weirdly sliding on slopes starting with Sonic 3).

Also in Sonic and Knuckles, probably as a way to combat the anomaly associated with turning around while rolling in the previous games, Sonic unrolls if absolute gsp falls below 0.5.

Rolling Jump

In Sonic 1, 2, 3, and Knuckles, you can't control Sonic's trajectory through the air with the LeftRight buttons if you jump while rolling. This makes it kind of hard to Spindash to gain speed, and then make a precise jump. Though, in Sonic 3 and in Sonic & Knuckles, you can regain control of the directional keys if you perform a Insta-Shield, or any other jump ability.

However, in Sonic CD and Mania, you can control a jump made while rolling, as if it were a totally normal jump. This is probably more fair to the player.