I could really use some advice from some experienced users. I apologize for the long post, but I hope giving a more detailed explanation/questions will help me find better answers. Let me start by telling you what I'm trying to accomplish, and what problems I'm having/what I don't understand.

For starters, I'm working in Lite-C, and I'm new to this language and 3DGS. However, I've got limited experience with application programming in C++, but never any 3D worlds/games. I've read the manuals and Lite-C tutorials till I'm blue in the face, several times. laugh

What I'm trying to do is start a coding template for vehicle movement by physics for a big project my team and I are undertaking. Right now I'm trying to get a Panzer IV (tank) moving around like a tank should. This is really a testing project, and when it's done, I'm going to "splice" or cut/copy bits of code out of it to use in the real game/sim.

So, here's my first problem, which should be fairly simple:

I want the "e" key to crank the engine when pressed once, and shut down the engine when pressed a second time. Of course, it should start looping the sound of a running engine. I tried doing this is several ways, none of which worked properly. Some ways would start the engine sound loop, but it wouldn't stop. Other ways did nothing. And some even crashed the program or made my camera unlock from the tank. Here's an example:

Code:
var engine_state = 0;

....

function start_stop_eng();

function start_stop_eng();
{
	if(engine_state == 0)
	{
          engine_state = 1;
	  ent_playloop(panzer,tankidle,77);
	}
	
	if(engine_state == 1)
	{
          engine_state = 0;
	  snd_stop(tankidle);
	}
}

....

action tank_controls()
{
 ....

    if(key_e)
     {
       start_stop_eng();
     }

}

...


Now I understand why this won't work. The function starts with engine_state at 0, so it turns it to 1. The next if() becomes true due to this, and turns it back to 0 and nothing seems to happen. But I've tried this many different ways, and can't get anything to do the job. I've even tried some very complex, even redundat if/else branching to no avail. About a week ago, I finished a complex GUI for this game, and had no such problems. Maybe I'm just not thinking straight because I haven't slept well in days, heheh... blush Please give me some ideas if you can.

**************************************************************

Now, the other prob:

I've never done physics before, except for playing around with small levels where you kick balls around, or push things. No car/vehicle physics; ever... At first, I tried to simply set the ph_type of the tank to a box, and just push it around on the terrain. This didn't work. The tank didn't want to move at first, then it would "explode" at tremendous speed. Even when I changed gravity, mass, friction, damping, etc, it didn't work right... still "exploded", or just refused to move...

So I decided I need to go ahead and program this similar to a car, or truck. We have excellent looking models (only basic skins as of now though) for our tanks and vehicles. We did the tracks like this to save polies:



The geometry won't be moving, only the texture will, and make it appear that the tracks move.

So I figure to get this working correctly, I need to make several invisible wheels on each side, somehow. The manual says you have to add constraints, and use ph_wheel. However, there's no good example on how this is done. I can't find any tutorials or clear examples of this anywhere on the net either. I've looked at some other people's car projects, and I really don't know what they're doing with it or how it's used...

I don't know if I have to use an actual physical object (model/entity) for these wheels, or if they can just "exist in code". The manual doesn't say, and there's no info I can find about it. There are also no tutorials for 3DGS car physics around. So I'm pretty much stumped here... cry

If anyone can point me in the right direction, and help me understand what to do, I'll be eternally grateful. I've just never done this before, and can't find any of the info I need on this. Please try to give me as detailed an answer as possible. Sorry again for the long post.

Thanks!

P.S.- Here's the source as of now... I've deleted most of the "junk" code that wasn't working for me, and it's down to the bare working parts...

Code:

///////////////////////////////////////////////////////////////////////////////////////////////////
// Icluding...
#include <acknex.h>
#include <default.c>
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Vehicle movement template... testing a tank... by Keinmann...
///////////////////////////////////////////////////////////////////////////////////////////////////

// Using the desert skirmish map, "Das Sandbox"...

// Declaring variables

var engine_state = 0;

//Declaring entity pointers

ENTITY* panzer;

// Defining movement vectors

VECTOR vSpeed, vAngularSpeed, vForce, vMove, vAhead;

// Defining sounds

SOUND* tankidle = "tankidle.wav";

// Declaring functions

// Tank movement code...

// Defining actions

action tank_controls()
{
	wait(1);
   set(my,POLYGON); // Make the engine interpret collisions by the polygon and not bounding box
	
	// Set the tank's physical properties.
      phent_settype(my,PH_RIGID,PH_BOX);
      phent_setmass(my,2,PH_SPHERE);
      phent_setfriction(my,5);
      phent_setelasticity(my,7,100);
      phent_setdamping(my,27,5);
	

	while(1)
	{
		 // Update camera positions
      camera.x = my.x - 55;      // Position relative to tank's x position
      camera.y = my.y + 0;      // Position relative to tank's y position
      camera.z = my.z + 25;      // Position relative to tank's z position
      // Set camera tilt and pan in order to look at the tank.
      camera.tilt = -15;
      camera.pan = 0;
      wait(1);
      
    if(key_e)
     {
     	 // ..............
     }
     
      //   Check to see if the player has fallen off the level i.e. the z value is less than minus 200
      if(my.z < -200)
      {
         phent_enable( me, 0 );      // To move physics enabled entities to an xyz position you must first disable physics for that entity
         my.x = 0;                  // Place at 0,0,80 (The 80 is so it spawns high enough above the level. You may need to change this with custom levels)
         my.y = 0;                  //
         my.z = 1000;
         phent_clearvelocity(my);   // Remove any speed and direction from the entity
         phent_enable( me, 1);      // Re-enable physics
      }
	}
}

// Collision detection/properties for objects
action terrain_prop()
{
   wait(1);
   c_updatehull(my,1);   // Update the "hull" of the object (helps engine with collisions)
   set(my,POLYGON);      // Make the engine interpret collisions by the polygon and not bounding box
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN ///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

function main()
{
	video_mode = 8;
	shadow_stencil= ON;
	video_screen = 1;
	mouse_mode = 0;
	wait(1);
	
	//load level "Das Sandbox"...
	level_load("tryintankin.wmb");
	wait(2);
	
	// Gravity
   ph_setgravity(vector(0,0,-500));
   
   // Create sky
   ent_createlayer("skycube+6.tga", SKY | CUBE | VISIBLE, 0); 
   wait(2);
   
   // create player/tank entity
   panzer = ent_create("panzerIV_skin_wip.mdl", vector(-488,-848,1500), tank_controls);
}



Like I said, I deleted all the "junk" code out of this, because it wasn't doing me any good...