Difference between revisions of "Worm Walking"
From Worms Knowledge Base
Line 8: | Line 8: | ||
* Frame 1: 0.50 | * Frame 1: 0.50 | ||
* Frame 2: no motion | * Frame 2: no motion | ||
+ | |||
* Frame 3: 0.50 | * Frame 3: 0.50 | ||
* Frame 4: 0.50 | * Frame 4: 0.50 | ||
Line 24: | Line 25: | ||
* Frame 17: no motion | * Frame 17: no motion | ||
* Frame 18: no motion | * Frame 18: no motion | ||
− | |||
− | |||
[[Image:Walkexample.png]] | [[Image:Walkexample.png]] |
Revision as of 07:56, 13 December 2006
Walking can be performed in the game using the Left & Right arrow keys when you have control of your worm. The horizontal shift applied to the worm mask during a walk is determined by which frame gets displayed in the walking sprite.
Frame changes in the walking animation are caused by your controls, not by a FPS timer. This makes it possible for the sprite to have a FPS rate that is not a whole number, which happens to be the case. There are 15 frames in the sprite, 13 of which apply horizontal motion, and these get cycled 3 times per second. Worms runs at a steady 50 FPS. Not having a whole number for the rate of change means that the number of the frames in a cycle will vary. In 3 cycles, 2 cycles will have 17 frames and 1 will have 16 frames. (17 + 17 + 16 = 50)
(15 / 50 = 0.3, 0.3 * 3 = 0.9, 1 - 0.9 = 0.1, 0.1 * 100% = 10%) So 10% of the frames in the walking sprite get repeated with no motion applied to them. According to one of Deadcode's posts, the movement (pixels) in one walk cycle would look something like this:
- Frame 1: 0.50
- Frame 2: no motion
- Frame 3: 0.50
- Frame 4: 0.50
- Frame 5: 0.50
- Frame 6: 0.50
- Frame 7: 1.50
- Frame 8: 1.75
- Frame 9: 1.50
- Frame 10: 1.25
- Frame 11: 0.25
- Frame 12: no motion
- Frame 13: 0.25
- Frame 14: 0.25
- Frame 15: 0.25
- Frame 16: no motion
- Frame 17: no motion
- Frame 18: no motion
Worms wouldn't be very fun if your worm stopped moving every time a pixel got in your way. So to keep movement smoother, the game's physics coding initiates upto an 8 pixel check to see if your worm can be moved ontop of the collided pixel(s). Your worm gets shifted upwards if a negative collision is returned from the loop (1 to 8). If not, your worm will stop moving.
The above image demonstrates how the game calculates what to do when a collision occurs in the walking sequence. White refers to the worm mask, Green refers to the terrain mask, Blue refers to pixels where the two layers have collided, and the Red Arrow refers to the horizontal shift occuring in the frame.
Similarly, to prevent your worm from walking on thin air, the game needs to detect if there are degradations in the landscape as you are walking. This is done by initiating an 8 pixel check below the worm mask. Your worm gets shifted downwards if a positive collision is returned from the loop (1 to 8). If not, the gravity formula gets applied to the worm and the falling sequence is initiated.