Animal Jumping

From Worms Knowledge Base

Revision as of 09:50, 24 May 2021 by Mablak (Talk | contribs) (correcting Animal Turning section)

Jump to: navigation, search
(Up to Game logic)

Though we often blame luck whenever animals don't work as we expect, one can always determine where an animal will jump with a keen enough eye. Determining what kinds of obstacles make animals jump can be crucial in many situations, especially when you lack the ability to place a sheep or skunk exactly where you want, and need to send it on a run.

Sheep, skunks, and moles each have their own random jump height/range (and a few other distinguishing features), but the factors causing them to jump are the same. This article will cover their jumping and walking logic, and that of old ladies, salvation armies, and cows.

Going Uphill

It helps to look at an animal's behavior when it's moving on a long flat plane, because you can always think of the pixels the animal is standing on as its ground level. As the animal travels forward on this plane, it's only going to take into consideration objects close in front of it to determine when it jumps, and for now, we only consider objects above the height of the level plane, so no gaps.

So what happens if a sheep, skunk, or mole 'sees' a 1-pixel tall bump right in front of it? As long as there are no other objects to make it jump beforehand, it will always jump roughly 20 pixels from the bump horizontally, measured to its front legs. You can call this the animal's close-range jump. Now if we increase the height of this lone pixel, we find that the animal detects it and does a close-range jump at heights of 1, 2, 3, 4, and 5 pixels, but passes under the pixel at the 6, 7, and 8 positions. But when the pixel is raised to a height of 9 through 13 pixels, it will once again detect it, this time starting its jump around 50 pixels back (measured to its front legs), which you can call its far-range jump.

AnimalPixelDetection1.PNG

The picture below shows a sheep approaching a column of pixels. As long as there exists even one of the yellow pixels in this column, the sheep will detect it and do its far-range jump. If this column had no yellow pixels, but any of the red ones, the sheep would do a close-range jump. And if the column happened to have no yellow or red pixels, it would simply pass under. This strange detection method is explained by the 7-pixel wide, 5-pixel tall collision mask each animal possesses; each pixel in the collision mask checks for a close-range or far-range pixel at its own height and 8 pixels above it, and makes the animal jump if it finds one.

AnimalPixelDetection2.PNG

In real games, animals usually encounter large chunks of land instead of thin columns of pixels. To determine when they'll jump, one simply needs to find the first column of pixels that an animal will find itself roughly 20 or roughly 50 pixels away from. And if an animal lands in the right spot, it could perform a close-range or far-range jump up to 7 pixels closer than usual, if one of its back pixels detects land.

Going Downhill

Now we ask, what happens when an animal encounters a 1-pixel deep gap? As the picture below shows, it will continue walking, unaffected. Only once the gap is 4 pixels deep will an animal jump off the edge. The animal doesn't actually jump until its collision mask has nothing to support it, at the frame where it’s hanging in midair.

AnimalDownhillJumps.PNG

However, this doesn't mean that an animal will necessarily walk down land with a constant downward slope of say, 2 or 3 pixels. If an animal starts walking downhill, WA calculates where it would be in the next frame, given its horizontal velocity, and if the slope is too great between the starting and ending points, the animal jumps. When walking downhill or uphill, each animal differs, having its own signature max slope.

Narrow Area Behavior

You may have noticed that animals simply won't jump when they have a lot of land above their heads. In these situations, they can be said to be in "walk mode." In walk mode, animals will simply walk over any uphill segment that they can, turn at any uphill segment that exceeds their max climbing height, and fall straight down after walking off any edge or gap. Walk mode only applies to sheep, moles, and skunks. Salvation armies, old ladies, and cows will always perform their little hops.

Only pixels located at a height of 49, 50, 51, 52, or 53 pixels above the animal's ground level will place it in walk mode. The following picture shows the line of all pixels causing it to be in walk mode, for a given ground level. You can also see that a sheep simply walks over a 4-pixel bump, because it was in walk mode when it passed the close-range jumping point.

NarrowArea1.PNG

How much of an animal needs to be 'covered' overhead to place it in walk mode? A sheep, skunk, or mole only needs a single pixel within its 7x5 collision mask to be covered; any pixel composing the red line of the previous picture. Thus, a single pixel can be responsible for an animal missing a jump, as shown here.

NarrowArea2.PNG

This single red pixel, located 2 pixels to the right of the edge of the gap, causes the sheep to fall straight down. If this pixel were moved one pixel left, the sheep would only detect it some of the time. And if the pixel were lined up with the edge of the gap, the sheep would not detect it and would always jump. In this case, it's the back end of the collision mask that detects the pixel.

Narrow area behavior can also affect the jumps described in the Going Uphill section. Only one pixel in an animal's collision mask needs to detect a pixel of land to cause these jumps, so if an animal were exiting a low area and coming out of walk mode, it could perform a close-range or far-range jump up to 7 pixels closer to an object than it normally would.

Animal Turning

If we have a column of pixels (5 pix or higher) on some flat land, and a sheep, skunk, or mole happens to land within the close-range jump distance (its back end landing within roughly 20 pixels from the column), what happens? It will always hit the wall and turn around, and begin to jump in that same frame, because detecting a slope too high to climb triggers a jump.

AnimalTurning.PNG

This, along with instances of animals hitting walls in walk mode, is the basis for a lot of animal turning. Additionally, there is a 6.25% chance of an animal turning when it hits a vertical wall in midair, but only if it hits backside first, with horizontal velocity opposite the direction it's facing. This means it will never turn on the first bounce off a vertical wall, but has a small chance of turning if there is a 2nd bounce.

There also exist special cases of turning for skunks and moles. If a skunk has bounced off a side wall and has any velocity opposite to the direction it's facing, and you then press space to activate its fumes, it will immediately turn around in midair. Similarly, at any point when a mole is moving backwards from the direction it's facing due to bouncing off a wall, pressing space will cause it to launch in the opposite direction.

What Can Animals Walk Over in Walk Mode?

Sheep, skunks, and moles will walk over any level gap up to 6 pixels wide, as shown below. Sheep and skunks can often clear 7 pixels as well, with moderate likelihood. When not in walk mode, sheep, skunks, and moles will jump once they reach gaps either 7 or 8 pixels wide (and 4 pixels deep). The animals that are not affected by walk mode can clear surprisingly large gaps with their small jumps. Cows, old ladies, and salvation armies will clear 12 pixels with certainty. Cows will almost always fall into an 18-pixel gap or smaller, while old ladies and salvation armies will almost always fall into a 16-pixel gap or smaller. It is useful to note that holes made by firepunch or kamikaze will create gaps 19 pixels wide, should an animal attempt to cross them.

AnimalGaps.PNG

All animals except for moles will simply walk over bumps in the land up to 4 pixels tall, when they're in walk mode or start walking within 20 pixels of the bump. 5 pixels or taller and they'll just turn around. Surprisingly, the mole can travel over obstacles up to 8-pixels tall, only turning around at 9 or higher.

Climbing Continual Slopes

We know the maximum climbs each animal can perform, but in actual games, a short column of pixels will usually have even higher (or lower) elevated land right next to it, making the slope detected by the animal much steeper. To determine the maximum continual slope each animal can climb, there are a few worthwhile situations to consider.

  • Slopes with lots of solid land, causing an animal to continually jump as it climbs; this is the most realistic situation.
  • Thin slopes without much solid land, eliminating the possibility of jumping while climbing (except for the skunk, which jumps when climbing on a slope of 2).
  • Slopes when the animal is in walk mode.

For these three situations, this table gives the maximum slopes each animal can climb to the nearest half integer, along with a small illustration of what those slopes would look like in-game. Note that when going downhill, animals can only cleanly walk down land with a slope equal to or less than those listed in the third column of the table, with the exception of moles, who can walk down a slope of up to 7 in walk mode, and a slope of 3 otherwise.

ClimbingSlopes.PNG

Although real game situations rarely have perfect slopes, you can look at a given slope in a piecewise manner, to determine if any particular part of it exceeds the climbing capabilities of a given animal. For example, if you see a hill that mostly has a slope of about 1 or less, but has one part with a slope of 3 or higher, then you can determine beforehand that cows will climb the first part, but explode when they try to climb the steeper part.

Climbing Jumps

There's one more thing that can make animals jump. Any time a sheep, skunk, or mole climbs 4 pixels or more (note that sheep and skunks can climb up to 4 pixels, moles up to 8), they will immediately jump. This doesn't happen too frequently though, because usually some pixel above ground height will make the animal jump before making its climb.

This picture illustrates one situation where this can happen. Releasing the sheep within 20 pixels of this 4-pixel tall obstacle prevents it from jumping prematurely, but once it makes a 4-pixel climb, it immediately jumps.

ClimbingJump.PNG

Ceiling Barriers

Click to watch (W:A + Beta Update required) W:A replay: Deadcode’s Michelson-Moley experiment
Download · Info

When any animal is walking up a slope and encounters a pixel above it that would make it impossible for its 7x5 collision mask to proceed any farther, the animal is simply forced to turn around. WA checks to see if any land pixels are going to cross those of the collision mask in the next frame, and if so, it reverses the animal's direction before it's too late. However, because these checks are done on a frame-by-frame basis, if an animal were climbing fast enough, it could theoretically cross through a thin portion of land.

In the now infamous Michelson-Moley experiment of November 2011, programmer Deadcode discovered that moles are the only animals capable of walking through ceilings, as proven in this meticulously crafted replay. By creating a climb that keeps moles in walk mode to prevent them from jumping, they can continue to climb up an 8 pixel slope, passing through small portions of ceiling placed between the spots where WA checks for collisions.

See also

Personal tools