CRE8OR - game maker for anim8or

 


WATER IN GAMES


   In this tutorial we'll use Lizard Alien 6,

You'll need to update Cre8or in Version 0.075a in order to run this correctly.

NOTE: Texture are used in the tutorial for the purpose of teaching. These textures were borrowed. I do not hold authority over them.

The main drawback is that there is no transparency in Cre8or currently. However, it is a feature "soon to be."

Let's assume you have some terrain that has uniform. The most important part is that water is everywhere, where a certain "depth" is a smaller than a threshold value.

This is what none uniform water looks like. This is a bit more complicated and will not be demostrated in this tutorial:
  

 

Below is the type of water that we'll be using in this tutorial: notice that water is everywhere where the depth is a certain value.

 

It is important that you do not have parts of your level beneath the water's depth, which is not in water. I.E. Don't have "dry" underground caves beneath the water level. Because we'll asume that water is always at a certain "depth."

Our coodrninate system is the same as anim8or's and most game coords, Z is forward/back, Y is up/down, and X is left/right.


What is "depth?" Depth is a actually the "Y" position in our case.

So let's review what we expect:
(1) Player has a swiming idle animation
(2) Player has a swimming forward animation (no swimming backward now!)
(3) No (or almost no) gravity in the water.
(4) Player can go in an out of water.

Basically there'll be two states, in water, out of water. Once the water level reaches chest value the player will switch to swimming animation. If in swimming mode and water level reaches slighly less than chest value then switch to standing mode.

*Note: Remeber that when any bones are rotated, the physical sphere is still not rotated so collision will most likely be off; this will be handled later.

*Note: We'll asume that when swimming, the character's orientation will always remain parallel to the ground. Even though this is not the case for most games.

How do we know if the object is below the water surface? If the objects "Y" position is larger than the water's Y Position than it is above. Else, it is below.


Why do we eliminate/limit gravity in water and how? When an object is in a liquid material the density causes a force of bouyancy. It is greater in dense materials and less in less dense. Even the air pushes us up with a certain force; but water does a better job of pushing objects up.

The easiest way to do this is "if in water mode" then apply a upward force, thus opposing the downward gravitational force.

Ok so let's turn this explanation of a theory into applicable means; let me show you how it works.

Go to scene01 and add the "Initiation" event.

Now add a pice of code as shown

This adds a new global varaible and sets it to "0.0"
You could actually add this same peice of code to the "Scene: Create" event, just for clarity I added it here.

Now go to the "Water" entity

 

Now add another piece of code:
*****Note: Sorry I mispelled "position" in the following code.

This will make sure that the "water_level" variable is at the same height of Water Plane Object. This way you can more the Water object around in scene mode and not have to worry about changing "water_level"

 

Now things will get a little bit messy so try to hang on. Go to "Alien_Lizard"

 

Add a "IF" action and set the text to be: "get_position().y > water_level"

Add the brackets "{..." "...}" and the "Else"

 

Move/Drag the "Stand Straight" into the first brackets:


Now copy the Action Ctrl+C and Paste Ctrl+V, and move/drag that action into the other brackets:


Double click that "action" and set the sequence to "6" the swimming idle sequence

 


What does this do? It asks if the "Y" is greater than the water_level, if so then it should be normal, else he should be swimming.

Now that we know if the lizard is below the water, let us add some under water effects like, different camer, less gravity and more damping.

********Note: Make sure once you add the actions, you move them to the indicated locations of the pointer arrows.

First we'll add damping:

Now add the upward force, the exact value is hard to fine, I found 250 to be a good value in this case:

Now let's make sure the camera doesn't try to do anything silly:


Let's set the camera's height to be low:

 

Since we set the height and auto-height values for under water, we'll have to reset it for above water:

 

If you RUN it then you walk in the water your Idle animation chnages as well as the camera.

We need to now make sure when you walk or turn it doesn't do the stand up animations.

Copy this action (Select, Ctrl+C):


Go to the <LEFT> keyboard event and paste it as shown:

Do the exact same thing in the <RIGHT> keyboard event.

Go to the <UP> Event and add it as shown:

Add an "Else"

Now copy the "Move Forward" action and paste it at the bottom. Then double click it:

RECOPY the "If get_postion...."

Now go to the <DOWN> event and just add the IF copied action:

 

Now go to the <CTRL> event paste it there too:


Go to the <Shift> event:


I want the <Shift> key to have adual nature, underwater it should push the player upward. Now add another copy:

Double click it and change the text to the following:
get_position().y < water_level - 10

Add a upward force action, I found 900 to be a good value:



That is it for now!

I couple of things to note, in order to make the lizard tilt when swimming underwater, it would take a bit of more complicated coding so I did not want to dab into that.

To make sure water creatures do not escape the water, just add a "If" action to the step event and for the text use: get_position().y > water_level

Underneath that if add a Upward Force, but this time use a Negative value so it pushes the object down, back under water.


Tutorials Page




Copyrights (C) 2007 Keith Tabert
Thanks to R. Steven Glanville for Anim8or, Robin