Actions

Difference between revisions of "SPG:Special Abilities"

From Sonic Retro

(Insta Shield Information)
(Moved very character specific info to new Characters page)
Line 4: Line 4:
 
      
 
      
 
  <nowiki>//Variables
 
  <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
 
 
 
spinrev: the amount a spindash has been charged
 
spinrev: the amount a spindash has been charged
  
Line 22: Line 18:
  
 
  <nowiki>
 
  <nowiki>
spinrev -= ((p div 0.125) / 256); //"div" is division ignoring any remainder
+
spinrev -= ((p div 0.125) / 256)   // "div" is division ignoring any remainder
 
</nowiki>
 
</nowiki>
  
Line 32: Line 28:
  
 
  <nowiki>
 
  <nowiki>
gsp = 8 + (floor(spinrev) / 2); //this would be negative if the character were facing left, of course
+
Ground Speed = 8 + (floor(spinrev) / 2)   // this would be negative if the character were facing left, of course
 
</nowiki>
 
</nowiki>
  
Line 45: Line 41:
 
Once the button is pressed, Sonic will begin charging the Spindash.  After '''45''' steps have passed, he is ready to go.  When the Down button is released, Sonic launches at a speed of '''12'''.  If the Down button is released early, nothing happens.
 
Once the button is pressed, Sonic will begin charging the Spindash.  After '''45''' steps have passed, he is ready to go.  When the Down button is released, Sonic launches at a speed of '''12'''.  If the Down button is released early, nothing happens.
  
==Drop Dash (Mania)==
 
The drop dash in Sonic Mania isn't simply an instant landing spindash.
 
 
To charge Sonic up you release then hold the jump button while already jumping. The dash will take 20 frames to charge and once charged, when Sonic reaches the ground, your ground speed will be set. If the jump button is released before Sonic hits the ground, the move is cancelled.
 
 
As Sonic hits the ground, Sonic's ''gsp'' is calculated as normal. So at this point, Sonic will have a ''gsp'' value (as if he landed normally) which will be used in calculating the drop dash speed.
 
 
The game checks if you were moving backwards in the air. By backwards, I mean opposite to the way you were facing/pushing. For example, if your ''xsp'' was positive but you were holding & facing ''left'' at the time this would count as backwards, same for the other direction. In either case, Sonic's actual direction is then set to that which you are facing/holding.
 
 
===If you were moving forwards===
 
Sonic's ''gsp'' is set to his ''gsp'' divided by 4, plus (or minus, depending on direction) ''drpspd''. This speed is limited to ''drpmax''.
 
 
  gsp = (gsp/4)+(drpspd*direction)  ; direction is either 1 (right) or -1 (left), this speed would then be limited between the min and max values of -drpmax and drpmax
 
 
===If you were going backwards===
 
 
If Sonic's ''ang'' is 0 (flat), his gsp is simply set to ''drpspd'' (or negative ''drpspd'')
 
 
  gsp = (drpspd*direction)
 
 
Otherwise, on slopes, his speed is set in the same way as normal, but divided by 2 rather than 4. Of course, because you were moving backwards your ''gsp'' will be opposite direction of that which the dash is trying to propel you, so this results in a rather slow dash.
 
 
  gsp = (gsp/2)+(drpspd*direction)  ; this speed would then be limited between the min and max values of -drpmax and drpmax
 
 
 
A similar [[SPG:Camera#Spindash_Lag|Camera Lag]] effect to that used when spin dashing is used here too, to make the move more dramatic.
 
 
==Dash (Super Peel Out)==
 
 
Once the button is pressed, Sonic will begin charging the Dash.  After '''30''' steps have passed, he is ready to go.  When the Up button is released, Sonic launches at a speed of '''12'''.  If the Up button is released early, nothing happens.
 
  
 
==Shield Abilities (Sonic 3 & K)==
 
==Shield Abilities (Sonic 3 & K)==
Line 84: Line 50:
 
===Bubble Shield===
 
===Bubble Shield===
  
When Sonic does the Bubble Shield bounce, his X speed is set to '''0''', and his Y speed to '''8'''.  When he rebounds from the ground, his Y speed is set to '''-7.5'''.
+
When Sonic does the Bubble Shield bounce, his X Speed is set to '''0''', and his Y speed to '''8'''.  When he rebounds from the ground, his Y Speed is set to '''-7.5'''.
  
 
===Electric Shield===
 
===Electric Shield===
  
When Sonic does the Electric Shield jump, his X speed is unaffected, but his Y speed is set to '''-5.5''' regardless of its previous value.
+
When Sonic does the Electric Shield jump, his X Speed is unaffected, but his Y Speed is set to '''-5.5''' regardless of its previous value.
  
 
'''Note:''' All of the Shield abilities can only be performed once in the air.  Sonic must connect with the ground before he can perform them again.
 
'''Note:''' All of the Shield abilities can only be performed once in the air.  Sonic must connect with the ground before he can perform them again.
Line 100: Line 66:
  
 
If Sonic is to the left of the ring:
 
If Sonic is to the left of the ring:
   If the ring's X speed is less than 0, add -0.1875 to the ring's X speed.
+
   If the ring's X Speed is less than 0, add -0.1875 to the ring's X Speed.
   Otherwise, add -0.75 to the ring's X speed.
+
   Otherwise, add -0.75 to the ring's X Speed.
  
  
 
If Sonic is to the right of the ring:
 
If Sonic is to the right of the ring:
   If the ring's X speed is greater than 0, add 0.1875 to the ring's X speed.
+
   If the ring's X Speed is greater than 0, add 0.1875 to the ring's X Speed.
   Otherwise, add 0.75 to the ring's X speed.
+
   Otherwise, add 0.75 to the ring's X Speed.
  
  
Line 112: Line 78:
  
 
If Sonic is above the ring:
 
If Sonic is above the ring:
   If the ring's Y speed is less than 0, add -0.1875 to the ring's Y speed.
+
   If the ring's Y Speed is less than 0, add -0.1875 to the ring's Y Speed.
   Otherwise, add -0.75 to the ring's Y speed.
+
   Otherwise, add -0.75 to the ring's Y Speed.
  
  
 
If Sonic is below the ring:
 
If Sonic is below the ring:
   If the ring's Y speed is greater than 0, add 0.1875 to the ring's Y speed.
+
   If the ring's Y Speed is greater than 0, add 0.1875 to the ring's Y Speed.
   Otherwise, add 0.75 to the ring's Y speed.
+
   Otherwise, add 0.75 to the ring's Y Speed.
  
  
The ring's X and Y speeds are added to the ring's X and Y positions, moving the ring.
+
The ring's X and Y Speeds are added to the ring's X and Y Positions, moving the ring.
  
 
Here's some example code for the ring while magnetised
 
Here's some example code for the ring while magnetised
Line 129: Line 95:
 
{
 
{
 
//relative positions
 
//relative positions
sx = sign(sonic.x - x);
+
sx = sign(Sonic's X Position - X Position)
sy = sign(sonic.y - y);
+
sy = sign(Sonic's Y Position - Y Position)
 
 
 
//check relative movement
 
//check relative movement
tx = (sign(xspeed) == sx);
+
tx = (sign(Ring's X Speed) == sx)
ty = (sign(yspeed) == sy);
+
ty = (sign(Ring's Y Speed) == sy)
 
 
 
//add to speed
 
//add to speed
xspeed += (ringacceleration[tx]*sx);
+
X Speed += (ringacceleration[tx] * sx)
yspeed += (ringacceleration[ty]*sy);
+
Y Speed += (ringacceleration[ty] * sy)
 
//"ringacceleration" would be an array, where: [0] = 0.75 [1] = 0.1875
 
//"ringacceleration" would be an array, where: [0] = 0.75 [1] = 0.1875
 
 
 
//move
 
//move
x += xspeed;
+
X Position += X Speed
y += yspeed;
+
Y Position += Y Speed
 
}
 
}
 
</nowiki>
 
</nowiki>
  
==Sonic's Insta-Shield==
+
==Insta-Shield==
 
 
The Insta-Shield expands Sonic's hitbox giving it a width radius of 24 and a height radius of 24, resulting in an overall height of 49 x 49 (Hitboxes are complex, here's more about [[SPG:Game_Objects#Hitboxes|Hit Boxes]]). This lasts for 13 frames.
 
 
 
The Insta-Shield does nothing to Sonic's xsp or ysp. It does however allow him to control a rolling jump.
 
 
 
==Knuckles' Gliding/Climbing==
 
 
 
When Knuckles first begins gliding, his X speed is set to '''4''' in the direction he is facing.  Y speed is set to '''0''', but only if it was negative at the time, otherwise it is unaffected.  X speed then accelerates by '''0.015625''' every step.
 
 
 
Gliding has a top speed of '''24'''. This top speed is so high that it is unreachable anywhere in the game -- except for [[Mushroom_Hill_Zone|Mushroom Hill Zone]] Act 1, where Super/Hyper Knuckles can glide across the top of the level to achieve this speed.
 
 
 
During the glide, gravity is '''0.125''', which is weaker than usual.  Also, unlike a normal jump, gravity is only added while Y speed is less than '''0.5'''.  If Y speed is higher than that (say Knuckles was falling quickly when he began to glide), gravity is ''subtracted'' from Y speed instead, slowing his descent.
 
 
 
<nowiki>
 
if (ysp < 0.5) ysp += 0.125;
 
if (ysp > 0.5) ysp -= 0.125;
 
</nowiki>
 
 
 
When you let go of the button, Knuckles drops, and his X speed is multiplied by '''0.25'''.  When he hits the ground, it is set to '''0'''.  While dropping from a glide, gravity is the normal value, '''0.21875'''.
 
 
 
If you don't release the button, but allow Knuckles to glide into the ground and slide on his stomach, he has a friction value of '''0.125''' while sliding.  He starts to stand up as soon as X speed reaches '''0'''.  If you release the button after he has begun to slide, X speed is set to '''0''' immediately, and he begins to stand up.  Pressing Left or Right while sliding or standing up has no effect, but you can break into the standing up animation to jump if you press the jump button again.
 
 
 
If Knuckles hits a wall while gliding, he catches on, and can climb it.  He will catch on even if he's turning around, as long as his X speed is still in the direction of the wall.  He climbs up and down at a speed of '''1'''.  When Knuckles jumps off of a wall, his X speed is set to '''4''' in the opposite direction of the wall, and his Y speed is set to '''-4'''.
 
 
 
'''Note:''' Knuckles' knuckles deflect projectiles (just like the Shields do) while he is gliding.
 
 
 
===Turning Around===
 
 
 
When Knuckles is gliding, you can turn him around simply by tapping the Left or Right button.  Even if you let go, he will continue to make a full turn.  You can, however, reverse your decision and turn him back in the original direction before he makes a full turn.
 
 
 
You might think that turning around while gliding would be much like turning around while running on the ground.  X speed would be steadily decreased until it reached zero, and then would start adding in the other direction.  This is not the case, though, and a special method is used that preserves Knuckles' gliding speed.
 
 
 
When Knuckles is gliding, there is a value, which we'll call ''a'', that is '''0''' when he's gliding to the right, and '''180''' when he's gliding to the left.
 
 
 
When Knuckles begins to turn, his X speed is stored - let's call the stored value ''t''.  If he's turning from the left to the right, ''a'' is decreased by '''2.8125''' until it reaches '''0''' (which takes '''64''' steps).  If he's turning from right to left, ''a'' is increased by '''2.8125''' until it reaches '''180'''.  During the turn X speed is made to equal ''t'' times the cosine of ''a''.
 
 
 
<nowiki>
 
a += 2.8125 * -sign(t);
 
xsp = t * cosine(a);
 
</nowiki>
 
 
 
So, no matter how fast Knuckles is gliding, he turns around in the same amount of time, and his speed reverses fully.  During the turn, there is no acceleration.  It kicks back in once he's finished turning all the way around.
 
 
 
===Gliding Rebound===
 
 
 
An interesting side-effect of the fact that Knuckles' Y speed is not immediately blunted when he begins gliding while falling quickly is the "Gliding Rebound".  If you press the button to begin gliding just as Knuckles connects with an enemy or item monitor, his Y speed is reversed from the rebound just as he begins to glide.  Since gliding gravity is weaker than standard gravity, he goes soaring up into the air.  This is not necessarily a bug - it's actually kind of fun.
 
 
 
Once Knuckles is already gliding, rebound operates normally.  Since he can't exceed a Y speed of '''0.5''' while gliding, though, the effect is rather weak.
 
 
 
===Underwater===
 
 
 
Strangely enough, Knuckles' gliding and climbing physics are totally unaffected by water. I suspect this is because the code performed when entering and exiting the water simply changes the acceleration, deceleration, and top speed constants (this is why falling in water nullifies Super Fast Shoes). Because Knuckles' gliding and climbing code operates irrespective of these values, his abilities couldn't be affected by water without rewriting the water entry and exit code. In your engine you may wish to halve some of Knuckles' speeds when submerged to be more realistic, unless you want to remain 100% true to the original games.
 
 
 
==Tails' Helitail==
 
 
 
When Tails begins to fly, his Y speed is unaffected.  However, since Tails has to release the button in order to press it again to fly, he can't possibly fly up faster than '''-4'''.
 
 
 
While flying, the variables are much like a standard jump.  He accelerates at '''0.09375''', and there is no separate deceleration value.  The normal [[SPG:Jumping#Air Drag|air drag]] calculation is performed, which means Tails can't fly horizontally as fast while moving upward than when moving downward.  The air drag cancels out the acceleration at an X speed of '''3'''.  There is no air drag while moving down, though, so he can reach an X speed of '''6''', the normal maximum.
 
 
 
While flying, gravity is '''0.03125'''.  Pressing Up or Down doesn't decrease or increase it.
 
 
 
Pressing the button doesn't cause an immediate loss of Y speed (like a double-jump), but instead a temporary change in gravity.  Gravity becomes '''-0.125''', and remains so until Y speed is less than '''-1'''.  Then gravity returns to normal in the next step and Tails begins to fly back down.  If Y speed is already less than '''-1''', pressing the button does nothing.
 
 
 
Tails can only fly for '''480''' frames, or '''8''' seconds, before getting tired.  The only difference being tired makes (besides the pooped-out expression) is that pressing the button doesn't have any effect anymore.  Gravity, and all other variables, remain the same.
 
  
As stated above if you have negative gravity, a '''Ysp''' smaller than '''-1''' is needed to return to positive gravity. This can cause issues when you hit a ceiling and your '''Ysp''' is set to '''0.''' Your gravity will remain negative and you will be stuck. In your engine, to prevent Tails from being stuck in negative gravity, you should reset the gravity to the positive value when a ceiling is detected.
+
The Insta-Shield expands Sonic's hitbox giving it a width radius of 24 and a height radius of 24, resulting in an overall height of 49 x 49 (more about [[SPG:Game_Objects#Hitboxes|Hit Boxes]]). This lasts for 13 frames.
  
'''Note:''' Tails' tails deflect projectiles (just like the Shields do) while he is flying.
+
The Insta-Shield does nothing to Sonic's X Speed or Y Speed. It does however allow him to control a rolling jump.
  
 
[[Category:Sonic Physics Guide]]
 
[[Category:Sonic Physics Guide]]

Revision as of 17:54, 29 March 2021

Variables

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

//Variables
spinrev: the amount a spindash has been charged

//Constants
drpspd: 8 //the base speed for a drop dash
drpmax: 12 //the top speed for a drop dash
drpspdsup: 12 //the base speed for a drop dash while super
drpmaxsup: 13 //the top speed for a drop dash while super

Spindash (Sonic 2, 3, & K)

When you first begin the Spindash, spinrev is set to 0. With every press of the button, spinrev is increased by 2, up to a maximum of 8. Furthermore, during the entire time the Spindash is charging, spinrev is being affected by the following calculation:

spinrev -= ((p div 0.125) / 256)   // "div" is division ignoring any remainder

This is exactly like the air drag calculation.

What this means is that the higher spinrev is, the faster it bleeds away toward zero.

When you release the Down button, the character launches forward at a speed of 8, plus floor(spinrev) - i.e. spinrev minus its fractional part (everything after the decimal point) - divided by 2.

Ground Speed = 8 + (floor(spinrev) / 2)   // this would be negative if the character were facing left, of course

Because the higher spinrev is, the faster it depletes, it is nearly impossible to get maximum thrust from a Spindash without the aid of a Turbo controller or frame-by-frame play. However, if you were able to, the highest speed achievable through the Spindash is 12.

Note: Water has no effect on the release speed.

Spindash (Sonic CD)

The Sonic CD style Spindash is much simpler. Many Sonic players may find it inferior to the Sonic 2 style, though, so you may not want to use it in your engine. Or, if you do, you might include a choice in the control options which one to use.

Once the button is pressed, Sonic will begin charging the Spindash. After 45 steps have passed, he is ready to go. When the Down button is released, Sonic launches at a speed of 12. If the Down button is released early, nothing happens.


Shield Abilities (Sonic 3 & K)

Flame Shield

When Sonic does the Flame Shield special move, his X speed is set to 8 in the direction he is facing, and his Y speed is set to 0, regardless of their previous values.

Bubble Shield

When Sonic does the Bubble Shield bounce, his X Speed is set to 0, and his Y speed to 8. When he rebounds from the ground, his Y Speed is set to -7.5.

Electric Shield

When Sonic does the Electric Shield jump, his X Speed is unaffected, but his Y Speed is set to -5.5 regardless of its previous value.

Note: All of the Shield abilities can only be performed once in the air. Sonic must connect with the ground before he can perform them again.

Ring Magnetisation

When Sonic has an Electric shield, nearby rings will become mobile and begin moving towards him in a unique way.

If a ring falls within a radius of approximately 64px around Sonic's position, they will become Magnetised and begin to move. When Magnetised, the rings have an X and Y speed and do not collide with anything (except for Sonic). In order to move correctly, we have to calculate how fast to move the ring, and in what direction to accelerate. The ring accelerates at 2 different rates depending on its relative position and speed, 0.1875 when already moving towards Sonic (in order to not pass him too quickly), and 0.75 when not (in order to quickly catch back up with him).

First, it does a check to see where Sonic is in relativity horizontally.

If Sonic is to the left of the ring:

 If the ring's X Speed is less than 0, add -0.1875 to the ring's X Speed.
 Otherwise, add -0.75 to the ring's X Speed.


If Sonic is to the right of the ring:

 If the ring's X Speed is greater than 0, add 0.1875 to the ring's X Speed.
 Otherwise, add 0.75 to the ring's X Speed.


Then, the attracted ring checks Sonic's relativity vertically.

If Sonic is above the ring:

 If the ring's Y Speed is less than 0, add -0.1875 to the ring's Y Speed.
 Otherwise, add -0.75 to the ring's Y Speed.


If Sonic is below the ring:

 If the ring's Y Speed is greater than 0, add 0.1875 to the ring's Y Speed.
 Otherwise, add 0.75 to the ring's Y Speed.


The ring's X and Y Speeds are added to the ring's X and Y Positions, moving the ring.

Here's some example code for the ring while magnetised

if (magnetised)
{
	//relative positions
	sx = sign(Sonic's X Position - X Position)
	sy = sign(Sonic's Y Position - Y Position)
	
	//check relative movement
	tx = (sign(Ring's X Speed) == sx)
	ty = (sign(Ring's Y Speed) == sy)
	
	//add to speed
	X Speed += (ringacceleration[tx] * sx)
	Y Speed += (ringacceleration[ty] * sy)
	//"ringacceleration" would be an array, where: [0] = 0.75 [1] = 0.1875
	
	//move
	X Position += X Speed
	Y Position += Y Speed
}

Insta-Shield

The Insta-Shield expands Sonic's hitbox giving it a width radius of 24 and a height radius of 24, resulting in an overall height of 49 x 49 (more about Hit Boxes). This lasts for 13 frames.

The Insta-Shield does nothing to Sonic's X Speed or Y Speed. It does however allow him to control a rolling jump.