Swimming optimization

From Ukikipedia
(Redirected from Swimming Optimization)
Jump to navigation Jump to search

This page serves mostly to document important considerations that should be kept in mind when attempting to optimize swimming movement. This page currently only deals with geometric concerns and does not yet address matters such as quickly reaching and maintaining high swimming speeds.

Quick Overview

Unless specified, "most useful swimming states" excludes water plunge, water punch ("water grab"), and water throw.

  • Straight Lines: For any given route, it is usually optimal to maximize the time Mario spends moving in a straight line unless water currents are involved.
  • Tess Turning: Avoid raw joystick positions with three digit coordinates near maximum pitch or yaw velocity.
  • Neutral/Opposite Target Yaw: If a quick decrease in yaw velocity is required, TAS Input's joystick X should be 0 or have the same sign as Mario's yaw velocity.
  • Neutral Wall Diving: In most swimming states, swimming against a wall with a vertical joystick position of 0 allows swimming at both maximum yaw velocity and pitch.
  • Floor Alignment: Hitting a floor will cap Mario's minimum pitch to be flush with the floor in most useful swimming states. B swimming can be used to circumvent this effect in order to efficiently gain height from sloped floors without sacrificing the ability to swim horizontally.
  • Ceiling Pitch Boost: In most swimming states, swimming into a ceiling adds an extra 256 units of downwards turning at the end of the frame, down to a pitch of -12543.
  • Zero Pitch Trick: If some frame would naturally have a pitch in the range of -255 to -1 while making Mario turn downwards, make that frame have pitch 0 instead for an extra frame of increased turning speed. This should NOT be used at the same time as Neutral Wall Diving.
  • Ledge Clipping: Wall hitboxes are so high and wide that swimming downwards into the floor near a ledge can cause a sizable wall push away from the ledge.
  • Ceiling Downwarps: Ceilings can be used to cut out periods of diving and allow that time to be spent covering horizontal distance instead.
  • Swimming Strength Conservation: If Mario has swam before, doing a flutter kick on the first frame possible when entering water allows Mario to reach maximum swimming speed faster.
  • Tighter Turning: By first turning in the opposite direction of where you want to go, the desired turn can be done tighter.
  • Overshooting Turns: Slightly overshooting a turn to a far target can give marginally more distance.
  • Precise Target Pitch: Alternating between two joystick positions can give target pitch values otherwise impossible to reach when swimming straight.
  • Mobius Turning: When turning, Mario can do a tighter turn by pitching away from 0. If he cannot move too far vertically, he can oscillate up and down to keep tight turning.

Detailed Explanations

Straight Lines

It should not be surprising that between two points in the water with no obstacles or collision nearby, the fastest path between them will be approximately a straight line. Turning should thus be generally kept to individual segments separated by straight lines, unless forced by surrounding geometry and obstacles. For example, intervening whirlpools and other water currents can make moving in a straight line extremely undesirable, as Mario begins to either strain harder and harder to maintain such a line or gets pulled far off course from it.

Tess Turning

Excessive joystick magnitudes can cause floating point rounding errors in the values of the joystick axes, which can sap 1 angle unit from Mario's target yaw velocity or target pitch due to integer rounding.

  • In the case of yaw velocity, Mario will turn 639 units per frame instead of 640, leading to increased deviation from an optimal turn on average every 16 frames.
  • In the case of pitch, Mario's pitch will be ±16127 instead of ±16128, effectively swimming at an angle 16 units away. With 28 speed, this means:
    • Vertical movement is reduced from ~27.99157 units to ~27.99048 units (~0.0038% reduction)
    • Total horizontal speed is increased from ~0.68715 units to ~0.73009 units (~6.2486% increase)

Neutral/Opposite Target Yaw

The absolute value of Mario's yaw velocity can only ever increase by 16 per frame. However, it can decrease (return to 0) at different rates. If Mario's desired target yaw velocity has the same sign as his current yaw velocity, it will change by 32 per frame. However, by holding neutral or in the opposite direction on the horizontal axis from Mario's current turning direction, it will change by 64 per frame. Interestingly, this means the input on the joystick's X axis for this in TAS Input will have the same sign as Mario's yaw velocity in the case that it is non-zero.

Neutral Wall Diving

In most swimming actions (but not all - water punch/throw are notable exceptions), hitting a wall while joystick Y is 0 will cause Mario's pitch to move away from 0 if Mario's pitch is 0 or below while maintaining Mario's pitch if his pitch is above 0. This is useful for maximizing both yaw velocity and pitch, as normally, trying to maximize one of yaw velocity and pitch will cap the other at a lower value. If this method is used to adjust Mario's pitch on a given frame, then it must be the only method used to do so. This is both due to the vertically neutral joystick requirement and the fact that the step results of 'hit wall'/'hit floor'/'hit ceiling' at the end of the frame are all mutually exclusive.

Floor Alignment

In most swimming actions (but not all - water punch/throw are notable exceptions), hitting a floor will cap Mario's pitch from below at the end of the frame, making him parallel to the ground if he was facing into it before. This can be annoying if a downwards angle is desired, but can also be used to very rapidly switch to upwards swimming. It is still possible to swim at an effective angle of up to 256 or 512 into the floor in these states, since Mario's joystick influence on pitch and subsequent actual movement occur earlier in the frame. Importantly, the fact that B swimming and water throws avoid this phenomenon means that B swimming can utilize sloped floors for efficient simultaneous horizontal and vertical movement, potentially avoiding the need to pitch upwards at all. If, while traveling up a slope, A swimming moves less than 16 units horizontally per frame due to extreme pitch, then B swimming up it may be preferable. Extremely tall and steep slopes may even make going out of the way to B swim up them desirable.

Ceiling Pitch Boost

In most swimming actions (but not all - water punch/throw are notable exceptions), hitting a ceiling will cause Mario's pitch to be decreased by 256 at the end of each frame that Mario's moving pitch is above -12288. This can still be counteracted exactly when Mario's pitch is already negative, and can even be overpowered when his pitch is non-negative. Importantly, though, it can be used to turn downwards an extra 256 units every frame. Since the limit is checked before the 256 units are subtracted and is a non-inclusive limit, it may in some cases be optimal to hold back slightly by up to 256 units to land a pre-movement pitch just above -12288. This will then have 256 subtracted, allowing the end of frame pitch to reach as low as -12543. This strategy of getting an extra frame of bonus turning bears resemblance to the next trick in the list, the Zero Pitch Trick.

Zero Pitch Trick

The rate that Mario can change his pitch without external influences depends on whether or not his pitch is negative (facing downwards). His pitch changes by 256 per frame when it is negative, but by 512 when it is non-negative, including when Mario's pitch is 0. However, target pitch values are rarely actual multiples of 512, leading to the possibility that Mario may lose a frame of higher pitch change due to slightly overshooting past pitch 0. Because of this, if Mario's pitch would naturally land in the range of -255 to -1 while holding upwards on the joystick, it is preferable to instead sacrifice a bit of turning so that Mario's pitch hits 0 on that frame instead. (This is all provided that a more negative pitch is desired to begin with, and that Neutral Wall Diving is not being used)

Ledge Clipping

While swimming, Mario only has 1 single step of movement in the frame, and wall hitboxes are not only located much higher than normal (10 units down instead of 30), but they are also more than twice their usual width. However, floors have the same exact hitboxes as normal. This means it is possible to get a large push while swimming around a ledge, provided Mario has a suitable approach trajectory. By swimming steeply down into a ledge such that Mario's intended next position is at least 10 units below the floor (ignoring integer truncation) and within 110 units of the edge, Mario can be pushed up to 220 units by that single wall. If a wall overlap is available and utilized, that may be able to double the resulting distance Mario is pushed up to 440.

Ceiling Downwarps

While swimming, ceilings naturally downwarp Mario to their height if he tries to enter them (so long as doing so would not put him under the floor), which can be exploited to travel large distances downwards instantly for free. This can allow more of Mario's speed budget to be put into horizontal movement, allowing Mario to cover not only more vertical distance in a given time, but more horizontal distance as well.

Swimming Strength Conservation

As Mario swims, his swimming strength increases from 160 to 280, increasing his top speed. This value is generally not reset when Mario exits the water and is also not reset by the first frame of a flutter kick, so by doing a flutter kick on the first frame possible when entering water, Mario will preserve his swimming strength and reach top swimming speed faster (with the caveat that Mario won't travel as far on the first several frames). This trick is more effective if Mario needs to turn immediately on entering a water level, as the short term distance loss from this trick won't matter as much. Note that the trick does not work with some water levels (e.g. Secret Aquarium), and you need to have swimming strength conserved from a previous swim (which can be from a different course).

Tighter Turning

When turning, Mario's yaw velocity increases at a linear rate, and when finishing a turn, his yaw velocity drops at quadruple the speed. As a result, if Mario needs to turn by a medium to large amount, he can turn faster by first turning in the opposite direction for a handful of frames. This will give Mario a higher yaw velocity when making the turn, allowing him to swim to the next destination faster. It is unknown how many frames of opposite direction turning is optimal for this, but 11 frames of turning in the opposite direction works well. This trick still works if the turn requires collecting a coin, but it might not be faster if the coin is already collected at maximum yaw velocity. It may also be faster to turn in the intended direction for a few frames before doing the opposite direction turn.

Overshooting Turns

Since Mario's yaw velocity decelerates four times faster than it accelerates, it can be marginally faster to slightly overshoot a turn to a far target by adding up to 30 yaw velocity on the first frame of deceleration. However, this trick only saves up to a tenth of a unit in the best case while losing distance over shorter ranges, so this trick is only recommended for when less than a unit of distance needs to be saved to save a frame.

Precise Target Pitch

Joystick positions on the Y-axis can only achieve target pitch values that are multiples of 252. By alternating the joystick between two positions symmetric across the Y-axis, target pitch values not divisible by 252 can be achieved while still swimming straight. This can be used to swim up or down in a straighter line than otherwise possible. However, switching between joystick positions every frame can be tedious, so this is best done with a Lua script.