Home > notes > Swimming

Recipe for swimming

Ingredients:

  • 2 Underwater Animations (x number of allowed stances)
  • 1 template for character with extra animations added
  • 2 Command gizmos + 2 commands - to turn swimming on and off
  • 1 modified select_walk skrit to choose the right animation when swimming is on.
  • 1 modified select_fidget skrit for when the movement stops.

Optional:

Swimming equipment (Mask, Tank, Fins) - if constituted as a Set, then an extra entry in set_definitions.gas. Note that requiring equipment to swim restricts the possible weapon stances, and thus reduces the number of animations required.

Method:

First create your animations in gmax

Click for larger image Click for larger image

Add the animations to the template.

Next write a whole shovelful of skrit.

The GoBits singleton is a manager for an associative collection of data that can be looked up by owner (Goid*) and name (string). I used a Bool that I named "swim". GoBits.RSSetGoBitBool(goid*, "swim", value) will turn swimming on and off, while GoBits.GetGoBitBool(goid*, "swim") will return whether swimming is on for that character.

I created templates for two new command gizmos - cmd_dive and cmd_surface, which connected to skrits of the same names. These skrits live in world/contentdb/components/commands, and the gizmo templates go in world/contentdb/templates/command. Note that one is singular and the other plural, be careful creating your folders!

Each of these extracts the goid from the message that activates it and calls the RSSetGoBitBool function to change the "swim" bit. Placing a pair of these next to each other at the point where the animation change is needed turns swimming off, then immediately on if going into the water, or on, then off again coming out. The gizmos have self-triggers added (using a bounding box) when placed. The skrit for each of these sets the GoBits value and reduces her speed when swimming, or reverts it to normal when she resumes walking/running. I can add additional processing later (e.g. preventing inventory access while underwater so that the required equipment can't be removed).

The standard select_walk skrit (in art/animations/skrits/) has logic to select between run and walk animations depending on speed. I added the test for swimming before this, and made the test for a speed option depend more than one animation, rather than exactly two! This has the effect of requiring that swimming be the third animation, but the first two can be identical.

Select_fidget is a much more complex skrit than select_walk, as it has to consider more context. The standard templates have a "nervous" fidget for when enemies are near, and a more relaxed one for the other situations. It also has to evaluate whether other activities (such as auto-casting buffs) need to interrupt the fidget. I thought I had found the common location for selecting the subanimation in the included "k_job_c_mcp_fidget_utils" file in the GetAnim$ function, but nothing happened when I changed the code there.

I ended up having to replace select_fidget completely, remove the GetAnim$ function from the include file and move its logic to select_fidget and add the swim code there. That also meant changes to job_fidget to remove a call to GetAnim$

I also wanted her to breath out bubbles as she swam. That is another story worthy of its own page.

The optional equipment needs two meshes for each piece (as worn and as ground item), with textures for each (I made everything plain black and shared one). Each item also needs an inventory icon. The scuba tank is a shield, just like her backpack, and the fins replace her shins as well as her feet - the join is hidden by a band (to hold a knife on one leg). The mask is a regular helmet, and since there is a fixed main character in my game, it can include her head and hair just like her glasses do.

Click for larger image

Since taking this screenshot I've added a waist strap to the tank.

There is a door that checks whether all the items are equipped before it will open. That door closes again when she leaves the flooded area, so it can check again the next time she tries to go in.


After doing all this I found Witness' notes on adding animations for her Light/Dark Elves project - in her case for the new weapons. I assume Xaa used a similar method to have Pooka and others swim in Mageworld.

Lara 3