================================================================================
"Other_Models2.txt" - More tips for using Move_Car script for other model types  Version 1.1  April 21, 2002
================================================================================
Line numbers are given to help you find different parts of the script.  (The script 
currently has 1,088 lines of programming.)  If your text editor does not display line 
numbers, they will still help you know the approximate location.   Because future 
releases of the script may have more, or less, lines of code, the numbers are only 
approximate.  You can also use the "search" feature of your editor.

Script lines are shown in brackets:       [  This is what you will see in the script; ]
The brackets "[" and "]" are only for the documentation, to show that a line was taken  
directly from the C-Script file.    ***  Do NOT include them in your script!  ***
_______________________________________________________________
SNOW SKIERS  (Downhill and Cross Country)
SNOWBOARDERS

Snow Skiers should adapt pretty easily.
The biggest concern will probably be turning off things you don't need, such as the
speedometer, tachometer, rear-view mirror, gear displays and the throttle thermometer.

Go to line 51 in the "Move_Car.wdl" C-Script file.  There you will find table entries 
to turn off most of the things you don't want.  Let's take a look:

   [  // Features you can turn off - Set to zero for OFF, non-zero (1) for ON  ]
   [     var Eng_Snd_On = 1;      // Engine sound    ]
   [     var Horn_Snd_On = 1;    // Horn sound       ]
   [     var Squeal_On = 1;         // Tire squeal sound    ]
   [     var RV_Mirror_On = 1;  // Rear_View Mirror  ]
   [     var Car_Hud_On = 1;     // On-screen displays  ]

We can set all of those to zero, and they will be gone!  (You may want to go into the 
"Move_Car" C-Script and completely eliminate those functions, so the effects won't be
running in the background, and just invisible.)
However, if you can find a sound file with the sounds of a skier "schussing", you might 
want to leave that one turned on.  Just change the "engine" sound file, at line 67:
   [  sound engsound = <Car_Engine.wav>;  // Engine sound file  ]

We also need to change the number of gears we have.  "One" should be plenty for a skier!
Set "num_gears" to "1".  (Line 31)  
   [  var num_gears = 6;  // Number of forward gears (at least 1, but no more than 6) ]

Then we need to make an entry in the gear_ratio for first gear.  (line 1051):
   [ gear_ratio[1] = 2.97;     // First gear  ]
We can probably make that equal to one, but you may want to experiment with it.

The animation of your model comes from animation frames you provide, and your additional 
script.  Remember - the "Player_Car" action treats your model as if it is only a "box".
It doesn't know if your model is a car, a skier, a 40 ton mechanical robot, or just a cube.

You may want to use the calculated variable "steering" to know when to animate the skier
to move his knees for a turn.  Default "Steering" goes from -6 to +6.  (line 139)
   [ var steering = 0;       // steering force  -6 to +6 (calculated) ]

The skier (or snowboarder) will automatically fly off of moguls or ramps, if there is 
enough speed.  However, "helicopters", "goofies", and other airborne tricks will have 
to be added through your scripting and animation frames.  Check the variables "Airborne" 
(line 104) and "My_Height" to see if you have enough height for the trick.  (My_Height is 
defined in the "Standard Templates", and calculated in the function "Car_Scan_Floor", line 868.)

You will have to decide if you are going to "Power" the skier, or just let gravity do the work.
By keeping the throttle and "engine", you will be able to better simulate "edging", "poling",  
"skating" and have more control over the speed, especially for cross country skiers.  
But for more downhill realism, you may want to disable the throttle, and use only gravity and 
the steepness of the slope of the hill.  (You will still want to use the throttle for "braking".)

Take a look at the "Table Entry Area", lines 21 through 49.  You will want "Hill_Effect",
"Turn_Effect" for slowing in the turns , "Corner_Lean",  and maybe some "steer_damage" 
when you are skiing on ice.  You will probably want to set "Rock_Back" to zero, to eliminate
that effect.  (Maybe not - it might show realistic starting and stopping effects, depending on 
your skier model.)  Adjust "Accel_Val" to give your skier realistic acceleration values.

Play with the values in Brake_Torque,  Car_Weight, differential_ratio, Drag, gear_efficiency,
and Horse_power until your skier behaves the way you want.  (Not very appealing names for 
those labels, (for a skier), but the concept is pretty much the same!)
______________________________________________________________________
SKI JUMPERS

Follow the instructions (above) for "SNOW SKIERS".  You will likely want your  throttle to 
do little more than release the "brake", when you move it to full forward.  Gravity should take 
you down the ski jump.

There is one effect you wil probably want to play with, and that is the amount the model "tips 
forward" when airborne.  Let's take a look at line 932 in the "Move_Car" C-Script:
   [ else { my.tilt += -0.2;}  // Height over 5 - airborne, starting to nose down...  ]

You can either comment out this one line to get rid of the effect, or play with the value in the 
calculation to adjust the amount the skier "tips" forward, while in the air.  You could even make
the value a variable, and vary it with a random number generator, to add a little realism, and the
occasional disaster!

Going down the ski jump, the skier will be "on the ground".  The calculated variable "airborne"
(line 104) will be set to zero.
   [ var Airborne = 0;   // Set to one if my_height >= 5  (calculated)  ]
Once the skier reaches the end of the ski jump, the model will be "airborne" and the airborne
variable will be set one.  This would be a good time for the animation of your model to switch
to an "in the air" animation frame.
When the skier lands, the variable "airborne" will be set back to zero.  Now your animation frame
should display the image of a ski jumper that has just landed.

You can make the steering very sensitive, by increasing the table entry value for the variable
"car_sstrength", (line 39):
   [  var car_sstrength = 1;  // Increase to make steering quicker and more effective  ]
Make the value bigger to cause oversteer, and more difficult to steer down the ski jump.
(Don't make this too easy!)
Remember, "Turn_Effect" will decrease your acceleration and speed anytime you turn, 
even a little bit.  (Change the value in "Turn_Effect" for a stronger effect.)
The skier that has the best line down the ski jump, will fly the farthest!

To help you with scoring the jump, the "Move_Car" C-Script provides some calculated 
variables you can use, to automatically judge the competition:
   
line 117 [ var DTime = 0;  // Saved time spent falling (Calculated - changed each jump) ]
line 123 [ var HTime = 0;  // Saved value of Hang Time (calculated - changed each jump) ]
line 124 [ var Impact_Angle = 0;  // Saved value of the angle at impact, after falling (calculated - changed each jump) ]
line 125 [ var Impact_Speed = 0;  // Saved value of the speed at impact, after falling (calculated - changed each jump) ]

The "Impact_Angle" is in relation to level ground.  But if "Impact_Angle" has too big of a 
number, you may want to animate a "splat" or "face plant", and lower the score of the jump....
Same idea with "Impact_Speed".

Take a look at the functions "In_Air()", "On_Ground()", and "Drop_Hang()", lines 347 through 410.

Unfortunately, the C-Script does not measure the distance traveled over the ground, while in the air.
You can add that, fairly easily.  When the airborne variable switches to "1" (or airborne), save the 
value in "my.x" and "my.y".   When the airborne variable switches back to "0" (we have landed), 
(or use the calculated variable "Was_Airborne" (line 154) as a landing indicator), save the new 
values for "my.x" and "my.y".  The distance traveled over the ground can be calculated as follows:

   1.  Subract the old my.x from the new my.x and call it something like "dx"  (difference X)
   2.  Subtract the old my.y from the new my.y  and call it something like "dy" (difference Y)
   3   Distance traveled = square root of ( dx * dx + dy * dy)  
Notice that it doesn't matter if dx or dy is a negative number.  The answer will be correct, and positive.

See you in the Olympics!
_________________________________________________________________
WATER SKIERS

There are a couple of ways to simulate a water skier.  You can make the boat the "parent", and 
the skier would be the "child"; or the waterskier the "Parent", and the boat would be the "child". 
The "Child" gets it's position from the position of the "parent".  
Or - you can try to coordinate and move them as independently controlled models.

A cheap and easy way to do a water skier, if the boat is the parent, is to use the same code the 
Car_Cam does, when the camera is following the player.  Instead of calculating the position of 
the camera, instead we calculate the position of the waterskier!

Open "Car_Cam.wdl" and look at the function, "Tail_view()" (line 37).
We will need to create an entity, called "skier".  Then copy the Tail_View() function, and 
every place it says, "camera", let's substitute "skier" instead.  (Take a look at the 
documentation file "Cam_Script.txt" to understand what the camera script is doing.)
Our new function should look something like this:
   /////////////////////////////////////////////////////////////////////////
   // Desc: Move_Skier - waterskier is directly behind the boat, and at the same height
   //                      The boat is the "player"
   //
   function Move_Skier()
   {
        // place waterskier behind the boat (player's location)
         skier.x = player.x + cos(player.pan) * (-300);  // Offset from player
         skier.y = player.y + sin(player.pan) * (-300);  // Offset from player
         skier.z = player.z            // Same height as the boat (You may need to adjust this)
         skier.pan = player.pan;   // Waterskier faces the same way as the player (boat)
         skier.tilt = 0;                  // Fixed waterskier forward/backward tilting  (None)
         skier.roll = player.roll;    // Waterskier leans the same as the boat, in turns
}   
    
That's it!  Your waterskier will follow the boat around, wherever it goes!  
(Don't forget to draw in a tow rope between the boat and the waterskier.)

The bad news, is the waterskier will not be able to steer, and may not jump ramps the 
way you want.  For those effects, you can make the waterskier the player, the boat the
child, and have the boat get it's position from the steering of the waterskier.  Or - leave 
the boat as the player, but add steering keys for the waterskier.  That's something you
will have to experiment with, depending on your models, and what you are trying 
to accomplish.
_________________________________________________________________
Power Boats, Sail Boats, Merchant Ships, Fishing Boats, Navy Ships

Boats are fairly easy to simulate with the Move_Car C-Script.  You will generally want to
set "Num_gears" to one, and select a gear ratio for gear number one that will make your
ship perform the way you want.  (See lines 31 and 1051)

For larger ships, and navy ships, you can follow most of the guidelines for "TRUCKS" in 
"Other_Models.txt", including tuning the engine sound.  If you are simulating a sailboat, 
you will want to replace the engine sound with the "whooshing" sound of a sailboat gliding 
through the water.  (see line 67)

Don't forget the C-Script thinks your model is a "box", and it can't tell if your model is a 
truck on dry land, or a boat in the water!

You will want to disable squealing and maybe "rock back".  See SNOW SKIERS (above) 
for some tips on doing that.  ("Rock_Back" might be good for cigarette boats and 
hydroplane racing boats.)

For catamarans and other sailboats, you can use the technique for "Corner_lean" to make the
boat heel.  Instead of a steering force that causes the leaning, use the lateral force of the wind.
Take a look at how "Corner_Lean" was calculated, at lines 939 through 950.

If you are simulating a boat with a planing hull, you might want to increase the absdist.z
(or height) as the speed increases, to simulate the boat "lifting" out of the water, as it gets
up onto a plane.  You could add another line at the end of the function "car_scan_floor()"
to look something like this:
   [  absdist.z += abs(car_velocity) / 5;   ]  // Increase altitude of model as speed increases

The "5" in the above instruction is an arbitrary number, and will depend on the size and speed of
your model.  If your high-speed craft can go 50 knots, this will raise the boat by 10 quants.
( 50 divided by 5 equals 10 )  A boat that can only go 15 knots will be raised 3 quants.
(15 divided by 5 equals 3 )   So you may want to change that number to a 2 or a 3, to make 
your boat "get on a plane" sooner, and higher.  You can also use the "max" and "min" instructions
to make sure your boat doesn't go lower when you are in reverse, and also to put a limit on how
much it can raise up in the water.

Whether your boat has a bow wave, or a "rooster tail", (depending on speed), will be totally 
controlled by your animation frames, and the additional C-Scripting that you do.
_____________________________________________________________________
Airplanes, Helicopters, Gliders and Parasails, Hover Craft, and Submarines

I included submarines in this category, since they behave very similar to very slow jet fighters, 
except they are in the water, instead of in the air.  (The script won't know that!)
(Remember, the script thinks it's just controlling a "box"!)

For "game" type flight simulators, for a jet fighter, you can take some short cuts, and assume 
the aircraft is either "flying" or "not flying".  The takeoff speed for an F-16 is about 150 knots, 
an F-105 stalls at 155 knots, an F-117A stealth fighter takes off at 165 knots and lands at 150 
knots, a Phantom F-4C stalls at 151 knots and an F-4E stalls at 158.6 knots.  
You can make the "stall" speed 150 knots, and it will work for most modern fighter jets.

If the speed is less that 150 knots, you have stalled, and will be falling, according to gravity.
(The Move_Car C-Script already has this effect built in.)
If the speed is 150 knots or more, you can "steer" the aircraft up and down, the same way you 
steer left and right:
1. Add the joystick "Y" axis to the function "car_player_intentions()"  (line 732)
2. Add "tilt" and "roll" to the function "car_steering()" (line 988)
3. Modify the function "car_move_gravity()" (and the functions it calls) to allow steering
    when airborne, and for movement in the "Z" (or vertical) axis.

This simplified approach ignores the effect of "lift".  (As a plane goes faster, the wings
generate more "lift", which makes the aircraft fly.)  However, since a high-performance 
fighter jet can climb straight up, using only the thrust of the engine, the wings become more
like stabilizers, than airfoils that generate the forces needed to fly.  (So we can cheat a little,
and "steer" the plane upwards, rather than use "lift"!)

Most modern jet fighter pilots are concerned about AoA, or "Angle of Attack", as well as 
the velocity vector.  The combination of those two factors is frequently integrated into a 
single HUD display, to guide the pilot when landing.  The "Angle of Attack" indicator can
be easily created from the "my.tilt" values in 3DGS.  However, that only indicates the attack
angle with respect to level ground, and not with respect to the direction of flight.  This 
information would be useful when landing, but not for combat maneuvers.

Older (propeller) aircraft, gliders, and commercial aircraft will need to have the calculations
done for the lift vector.  (Hovercraft can use much the same technique as a planing hull
boat, as explained above, in BOATS.)

"Tail draggers" (or tail wheel aircraft) will need to have their tilt angle adjusted as they 
increase speed on take-off, until they are level.  Or, this can be done with animation 
frames and additional scripting.

Building a fully functional (and accurate) flight simulator can be a complex and challenging 
adventure.  The physics for flight uses most (or all) of the physics for ground vehicle motion.
While the "Move_Car" package might make a good starting point for a flight simulator, there
still remains a lot of scripting to produce a realistic flight simulation.

The "Move_Car" package does provide some assists and code samples to get you started on
creating the C-Script you need for your flying machine:

You will have to use a paint program to make the needles, speedometer and tachometer look 
like the types of instruments used in an aircraft.

The rotating needles for the speedometer and the tachometer can be used for several of the 
dials on the aircraft's instrument panel.

The "Rate of Climb" indicator can use the calculated variable "Vert_Speed" (line 152).

Make a dial with three rotating "needles" and you can have a three-hand altimeter.  
"My.pos.z" can give you the altitude data (in quants).

The technique used for the gear number display can provide any kind of number in a window, 
such as for an altimeter, a frequency indicator on a radio stack, or the "TO"/"FROM"/"OUT
of SERVICE" indicator on a VOR.

The rotatating needle on a compass dial can work like a gyro-compass, or a VOR.

The "on-screen" displays give you the clues you need to build a fully functional HUD, or
"Heads Up Display" on the "windshield" of your aircraft.
 
The technique used for the blue throttle "thermometer" arrow is identical to what you 
need to vertically move the side arrows on the HUD altitude and velocity scales.  
Framed within a window, this technique can even give you the HUD "Angle of Attack" 
ladder for the center of your HUD.

A RADAR altimeter is nothing more than one of the above display types, which shows
the value of "My_Height".
__________________________
If you are planning to make a flight simulator, take a look at Doug's Flight Simulator Workshop.
You can download it, for free, from the Conitec (3DGS) web site's download page.  It provides
a lot of good ideas, to help you get started.
____________________________
I look forward to seeing your flying machine!
__________________________________________________________________________
Bill McGonigal   (Willy)
April 21, 2002


