Very confused... need advice...

Posted By: Jaeger

Very confused... need advice... - 05/17/09 20:48

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...
Posted By: Jaeger

Re: Very confused... need advice... - 05/17/09 20:58

Oh... Ich spreche nur ein bißchen Deutsch. Wenn du kannst Englisch, bitte gibst mir die Antwort auf Englisch. Mein Deutsch ist nicht angemessen für Programmierung Konversationen. wink
Posted By: Jaxas

Re: Very confused... need advice... - 05/17/09 21:14

add to your code:
Code:
action tank_controls()
{
 var e_pressed;
 ....
     if(!key_e)e_pressed = 0;
     if(key_e & e_pressed == 1)
     {
       e_pressed = 1;
       start_stop_eng();
     }

}

for the sound,track and tank example i recomend you to study bulldozer demo wink
Posted By: darkinferno

Re: Very confused... need advice... - 05/17/09 21:38

i wouldnt make several moving wheels, i doubt that would make a believable tank, i personally think you took the right approach with ph_box, just make sure it isnt penetrating the level and use c_setminmax(my); so it uses the right hull and not a huge box, you just need to get it coded properly and that'll be all... good luck, i'll check back from time to time to help smile
Posted By: Quad

Re: Very confused... need advice... - 05/17/09 21:39

yes bulldozer demo will help you alot i think..

you can also do this fo engine thing
Code:
action tank_controls()
{
 ....

    if(key_e)
     {
       start_stop_eng();
       while(key_e) wait(1);//this will work but action will hang until user stops holding e.
     }

}


another solution would be:
Code:
action tank_controls()
{
    var e_on_last_frame;
 ....
     while(.)....
         if(key_e && e_on_last_frame==0)//this will only work once if player holds e
          {
            start_stop_eng();
          }
          //just before the wait
          e_on_last_frame = key_e;//this will let you know if e was being pressed on prev frame.
          wait(1);
     }
}

Posted By: Jaeger

Re: Very confused... need advice... - 05/17/09 22:05

Thanks for the tips/advice everyone.

I just downloaded the bulldozer demo. It's an excellent mini-game/demo, I must say. I'm about to look through the coding now.

I'm going to also try the things you guys mentioned, and see how it works out. I'll let you know the results.

However, if you guys wouldn't mind, I could still use some info about how car physics and wheels (and all that entails) works. I'm going to need to program some transport/hauler trucks, like the Opel Blitz truck, Kubelwagen, Morris Gun Tractor, etc. laugh

Oooh... I just noticed. In the bulldozer demo, they made each track a separate entity which is attached to the bulldozer itself. Do I have to do that? Because I do want to move the skin on each track to make it appear they move. I also need it to be differential, like a real tank (in other words, one track may stop or turn backwards, while the other turns forwards, like the bulldozer does). This also makes me wonder what to do with the turret and gun. I guess I can "rig" the turret and gun with bones, and rotate the bones in the coding, right? That would be easier for me than making every moving part a new entity! laugh
Posted By: MegaMarioDeluxe

Re: Very confused... need advice... - 05/17/09 22:26

If you want types to move, you could animate them in MED...
Posted By: Jaeger

Re: Very confused... need advice... - 05/17/09 22:32

Animate the skin in MED? I don't think you can do that, can you? The tracks geometry won't be moving, only the texture.
Posted By: Quad

Re: Very confused... need advice... - 05/17/09 23:02

the example of moving uvs is applied on the bulldozer demo, it does what you just need.
Posted By: Jaeger

Re: Very confused... need advice... - 05/17/09 23:21

Yes, I'm going to try that method. I think it's going to be hard to get the positioning correct though. smirk Maybe not. I'll have to take the tracks off of the original model, and make 2 separate models for each track I guess.

I still can't get the engine sound for starting/stopping to work though... I;m so frustrated with it, lol...
Posted By: Jaeger

Re: Very confused... need advice... - 05/17/09 23:26

It doesn't even work like this...

if(key_f)
{
snd_stop(tankidle);
ent_playloop (my,tankidle, 77,0);
}

if(key_g)
{
snd_stop(tankidle);
}

There's just no way to stop the sound... I thought the problem was measuring key presses, variables, and if/else branching... But this is a shocker. I can't even use two separate keys to start/stop the sound? Makes no sense to me. I've done things like this before, and never had the problem...

Posted By: Quad

Re: Very confused... need advice... - 05/17/09 23:28

ahh, that functions doesn't work that way..


var handle = ent_playloop (my,tankidle, 77,0);
snd_stop(handle);
Posted By: Jaeger

Re: Very confused... need advice... - 05/17/09 23:51

This is really weird... I just did that, and it doesn't work. I can't get the loop to stop playing by any method... Ugh... I've got a fully working GUI that plays sounds and music, and stops them on command. However, this just won't do anything for me...

Am I overlooking some rules or concepts about these function commands (related to ent_playloop/sound) that's giving me so much grief?
Posted By: MrGuest

Re: Very confused... need advice... - 05/18/09 00:25

heya, try something like
Code:
SOUND* snd_tankidle = ".wav"; //enter soundfile name here
var hnd_tankidle; //handle for playing soundfile

function toggle_engine(){
	
	//toggle to the new state
	engine_state = 1 - engine_state;
	
	//if engine is now on
	if(engine_state){
		hnd_tankidle = ent_playloop(panzer, snd_tankidle, 77);
		
	//if engine is now off
	}else{
		snd_stop(hnd_tankidle);
	}
}
//....

void main(){
	key_e = toggle_engine;
}
this is untested but will show you the use of sounds and handles

if this keeps switching on and off while you're pressing 'e', it'll be something inside you action, posting that code may help

hope this helps
Posted By: Jaeger

Re: Very confused... need advice... - 05/18/09 00:53

This is what I just tried (shortened form), and I'm about to try your code and post the results...

Code:
//////////////////////////////////////////////////////////////////////////////////

SOUND* tankidle = "tankidle.wav";

....

var epressed = 0;

var tank_handle;

....

function start_eng();

...

function start_eng()
{
	if(epressed == 1)
	{
	
  	tank_handle = ent_playloop (panzer,tankidle, 77,0);
  	
  	epressed = 2;
  	}
  	
  	
  	if(epressed == 3)
  	{

	snd_stop(tank_handle);
	epressed = 0;
	
   }
	
}

....
// This part is inside the tank's action, not main()...
if(key_e)
  { 
    
    if(epressed == 0)
    {
    	epressed = 1;
    	start_eng();
    }
    
    if(epressed == 2)
    {
    	epressed = 3;
    	start_eng();
    }
    
  }
//////////////////////////////////////////////////////////////


It appears to me I did the if branching just fine, as each condition is met after pressing e multiple times, respectively. But for some reason, the snd_stop command just doesn't work in my code. I even tried writing it a few different ways (i.e., with "var tank_handle = ....", and without, plus several other ways). The loop starts, and there's nothing I can do to stop it, lol. This has made me waste almost a whole day. frown

Ok, well I'm going to try what you posted above, and tell you what happened...
Posted By: Jaeger

Re: Very confused... need advice... - 05/18/09 01:14

@ Mr.Guest:

Your code worked almost perfectly. "E" starts the engine soundloop, and stops it... well, sometimes. For some reason, I have to wait about 3-5 seconds between keypresses. I guess that's not so bad, because a real Panzer IV would be about the same, heheh. You can't instantly start and stop it. But I would like to know why it does that.

Here's my source code, which is now working pretty much as I want it, with the exception of requiring the delay between keypresses...

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

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

// Declaring variables

var engine_state = 0;

var tank_handle;

var hnd_tankidle;

// Defining sounds

SOUND* snd_tankidle = "tankidle.wav";

//Declaring entity pointers

ENTITY* panzer;

// Defining movement vectors

VECTOR vSpeed, vAngularSpeed, vForce, vMove, vAhead;


// Declaring funtions

//////////////////////////////////////////////////////////////////////////////////////////////////
// Testing new function by MrGuest...                                                           //
//////////////////////////////////////////////////////////////////////////////////////////////////

function toggle_engine()
{
	
	//toggle to the new state
	engine_state = 1 - engine_state;
	
	//if engine is now on
	if(engine_state)
   {hnd_tankidle = ent_playloop(panzer, snd_tankidle, 77);}
		
	//if engine is now off
	else
	{
		snd_stop(hnd_tankidle);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////


// 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) 
    {
    	toggle_engine();
    }
  
      //   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); // Create a black backdrop for the level.
   wait(2);
   
   // create player/tank entity
   panzer = ent_create("panzerIV_sk_wip.mdl", vector(-488,-848,1500), tank_controls);
}



Can you explain to me why that worked and mine didn't? I'm just curious as to the difference. You know what they say, "Give a man a fish, and he eats for the day; teach a man to fish, and he eats for a lifetime..." laugh Well, you gave me the fish here. Can you tell me how you caught it? heheh...

Also, now that this works correctly, I can add something to my tank's action code like...

while(engine_state = 1)
{
...tanks movement/physics instructions here
}

...correct? That way, you can only drive the tank when the engine runs? That's how I originally planned to do this.

Thanks to all of you! I can't thank you enough for your time and patience! laugh
Posted By: Jaeger

Re: Very confused... need advice... - 05/18/09 06:06

Ok, well I've made each track a separate entity, they are passable, and will stay with the model properly. The toggle_engine function doesn't like me anymore, since I've added new things. Before, it was really tricky to turn engine on/off, and I had to hit the button multiple times. Now it cranks, but once again, won't stop.

I just moved on, and I'll try to fix that later. I made a while(engine_state ==1) loop in the tanks action, and have successfully tuned the sound when I press the buttons.

But here's an odd problem. I was trying to use the dozer demo as reference for how to animate my tracks' skins. Then I discovered, I can't even run the dozer demo if I hit "test run". It won't compile. I wonder if this is because the author used a newer version of A7 than I? His .exe works fine, but the code crashes in SED for me. And, you guessed it, it crashes due to the coding to animate the tracks! frown What could be the cause of this?

But now, I don't know where to go about animating the tracks' skins... I guess I'll try a few things, and I hope to hear from you guys again soon.
Posted By: Tobias

Re: Very confused... need advice... - 05/18/09 08:05

Well first you need make up your mind what problem you want to tell us, either the dozer wont compile, or it crashes, but hardly both at the same time.

When it wont compile, look at the line where an error is indicated, it probably uses a function that you dont have when your version is older. You should update your version then.

Your first code did not work because you were setting your "epressed" variable in such a strange way that the function was always called twice, and the sound was switched off immediately after it was switched on. Use the debugger, then you can easily see what happens in such cases. Without debugger, its just stumbling in the dark.
Posted By: Jaeger

Re: Very confused... need advice... - 05/18/09 08:26

The dozer demo won't compile. Sorry, don't know why I said "crashes" the second time.

" Error in Main line 142: 'u': is not a member of 'Entity' "

And that's where the coding for the little dozer's track animations go. However the dozer demo's .exe form works perfectly. That indicates to me my engine doesn't have something his does.

For my project, I tried a function like the one under the topic "vec_for_uv" in the manual. THAT made MY game crash. I usually need to see a good example of something to learn and understand it, and the example for this in the manual leaves me with nothing but questions. Trying to do a function like the one in the manual makes the compilation fail, due to the parameters in (). Without them, it compiles, but crashes when I try to run the function. And I don't understand why, because I've never seen this actually work, lol.

P.S.- I know why that first code I posted didn't work. Below I even said that it switched the sound on and off so fast it appeared nothing happened. It was just an example. The problem with the new code is that it no longer works if I add anything else to the program, and I just had to move on. At first, it worked... but only partially. It would switch on/off, but sometimes wouldn't. I had to wait several seconds between keypressed, and occassionally that wouldn't even work. Now it just doesn't shut off at all... again...
Posted By: Tobias

Re: Very confused... need advice... - 05/18/09 08:50

I believe 'u' was implemented some time ago, so your version must be very old, you should update it, its free.

vec_for_uv works in all versions. But when you omit parameters in an example, it of course will crash because then, the functions dont get valid parameters.

You will see that there are two sorts of examples in the manual. The newer functions have full examples that you can directly copy-paste in your code, or they are even full programs. Older functions have short examples that only show how to use the function. They are not copy-paste and require that you understand what a parameter is used for and so on. For instance, the vec_for_uv example expects that you have a global vector "temp" defined somewhere, like many other examples.

Just some advice, I would NOT "move on" when something does not work. You have to understand why it does not work. There is ALWAYS a good reason. I cant see it either in your code but thats why you have a debugger. If you just ignore a problem in your code because you dont see it at first, the problem will stay, and will affect your code further, causing delays, frustration and so on.

Make sure that you code works 100% and not only 90%. When there is an unexplained delay or you have to press a key several times, dont give up until you found the reason, and then you'll say "Ah, why didnt I see it at first?" Maybe you have several entities "Panzer" in your level, but your function only works when there is only one. Or something like that.

Just some piece of advice from a fellow programmer who made the very same experiences with the first steps of programming.
Posted By: Jaeger

Re: Very confused... need advice... - 05/18/09 22:36

Thank you again, Tobias.

I'm trying to keep this program relatively small and simple. I'm basically trying to learn how to do these things which I'll need to do in the real game. I'm just about to fix the toggle_engine() function in a minute. But I agree, simply overlooking a problem and ignoring it is never good. All I did was re-do the Panzer and its tracks as separate entities, and the Panzer now creates its tracks when it "spawns" in to the level. I also fixed the skins, which had a funny alpha property that made them semi-transparent. Oh, and I need to find a way to dim the lighting on the terrain. I've got a few different terrains for this project. The one I call "Das Sandbox" is just a 5km X 5km desert terrain for testing vehicles, weapons, and other things. The "real" terrain is several hundreds of km in size, and covers the better portion of Libya (and yes, it's extremely accurate... I made it with space shuttle radar mapping). laugh I've got excellent high-res textures for them, but they appear far too bright under the sun.

But anyway, what do you feel would be the best way of going about animating the track skins? As far as placement, should they go in the tracks' actions, in the Panzer's action, or maybe in main()? I want them to precisely follow the movement of the tank, on time. They've also got to move differentially, for turning the tank, going in reverse, and "spinning" the hull. The Panzer IV G could *almost* turn in place, but it did have to move a little bit forward or backward. It couldn't turn on a dime like a modern American M1 Abrams or German Leopard II, lol.

And one offtopic question if anyone knows:

Is the Lite-C language capable of making a truly realistic and convincing flight model for aircraft, or should one stick to C++ or Java for that sort of thing?
Posted By: Petra

Re: Very confused... need advice... - 05/19/09 05:52

I would animate tracks by shifting the u or v values directly in the track entity action, getting the animation speed from the parent entity. For easier code, design the track entities so that they have the same origin as the main tank entity. This makes it easier to rotate them with the parent entity.


Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 08:05

I've fixed a few things. I was having a weird problem where the tank actually floated 2meters above the ground. I changed the model's origin, and it started working correctly.

Also, I was being silly when I was frustrated to death earlier, and changed the tank to a sphere to... uh... kick it around and vent some anger, lol. And I noticed the tracks didn't stay mounted to the tank. So I added:

my.pan = panzer.pan;
my.x = panzer.x;
my.y = panzer.y;
my.tilt = panzer.tilt;
my.roll = panzer.roll;

...and now the tracks stay mounted to the tank no matter which way it goes, rolls, turns, etc. I've also modified the tank model by adding some invisible, unconnected vertices at each corner, where I want the collision hull be. Then I used vec_for_vertex to get the position of each one, and use set_min/max to create a properly scaled bounding box. I guess I'm not quite as stupid as I appear! laugh LOL!


However, the method you mentioned for animating skins is problematic for me. It's done this way in the dozer demo everyone suggested. When I try to compile his source code, it crashes, due to the dozer's track action, right at the line where the u and v values are shifted. For some reason, my engine doesn't like those instructions. Plus, I can't find any examples of how to do things like this that actually work. The manuals are pretty vague on such topics...
Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 08:21

Hmmm... Does it require you to include mtlfx.wdl to use the u and v shifting instruction?
Posted By: Petra

Re: Very confused... need advice... - 05/19/09 08:35

No. I use the same effect for a waterfall and it works fine. mtlfx.wdl is for old A6 WDL only and can't be used in a lite-C file anyway. When you attempt to include that, you'll probably get tons of errors because you cant use different languages at the same time.

Maybe your version is too old? But then it would not crash but give an error message. Use the debugger to find the line where it crashes.

The u,v parameters are not in the manual, but they are in the atypes.h file with the remark "texture offsets", and thats what they do, at least in my game.
Posted By: EvilSOB

Re: Very confused... need advice... - 05/19/09 10:05

So whats the code you are "trying" to use with the tracks for the texture movement?
Can you post it? Say, the whole, current, tank action, or the track actions if its in there.
Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 11:30

Originally Posted By: Petra
No. I use the same effect for a waterfall and it works fine. mtlfx.wdl is for old A6 WDL only and can't be used in a lite-C file anyway. When you attempt to include that, you'll probably get tons of errors because you cant use different languages at the same time.

Maybe your version is too old? But then it would not crash but give an error message. Use the debugger to find the line where it crashes.

The u,v parameters are not in the manual, but they are in the atypes.h file with the remark "texture offsets", and thats what they do, at least in my game.


Sorry, I said "crash" again when I meant it won't compile and gives an error message. I tried including atypes.h at the top of the dozer demo code, and it still won't compile. And that's a program I KNOW is coded correctly.

It says:

"... 'u' is not a member of ENTITY..."

I think that's line 142.

It had some other errors at the first few lines when I first tried to compile it myself. I added default.c and acknex.h, and then it started getting errors at that line. So including atypes.h in the dozer demo still won't compile.
Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 11:36

Originally Posted By: EvilSOB
So whats the code you are "trying" to use with the tracks for the texture movement?
Can you post it? Say, the whole, current, tank action, or the track actions if its in there.


Well, I'm not even trying to animate the track skins anymore at the moment. I deleted the "junk" code I was using earlier. I figured I needed to get the tank moving around properly first, then figure out how to animate the track skin and make it match the movement of the tank.

The tank now is properly acting as a physics object though, which is much better than before, and the tracks stay on at the right place. Oh, I also fixed the problem where toggling the engine made the camera unlock from the tank. I needed to include the camera update code in the while(engine_state ==1) loop in the tank's action. But here's the thing bugging me now:

How to get the camera to "chase" the tank, and pan with it, staying directly behind it at all times. In addition to this, the vector of the forces I'm applying need to be linear, and in the same direction the tank is pointing. Right now, the force just pushes the tank in the +x direction, even though I've tried vec_rotate. The camera is also screwed up. It does follow the tank, but when the tank pans, the camera pans behind it, and you lose visual on the tank. I haven't figured out how to make the camera pan while keeping the tank in view.
Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 12:16

This made the chase cam concept work better. It's still not quite how I want it though:

// Update camera positions
camera.x = panzer.x - 50 * cos(player.pan);
camera.y = player.y - 15 * sin(player.pan);
camera.z = panzer.z + 25; // Position relative to tank's z position
// Set camera tilt and pan in order to look at the tank.
camera.tilt = panzer.tilt -15;
camera.pan = panzer.pan;

Now I've got to figure out how to ensure force is only applied in the direction the tank is facing for forward/backward movement...

EDIT: Silly me, once again. Changing "...player.y - 15..." to "...player.y - 50..." has fixed the camera. Ok, camera problem solved.

But I still can't get the vector for forward movement working right.... It pushes the tank in the direct +/-x direction of the world, not the tank, or it just does nothing if I change things...
Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 15:53

Ok, I've fixed this so that the force now pushes in the tank's facing, rather than just the world's x axis. Major improvement! laugh

Only thing now is I get a little "slip n' slide", or "yaw/pan" as the force pushes the tank around now (probably due to the friction/collisions with ground as it moves). As you know, tanks can't move sideways, not even slightly, lol. So I wonder how to fix that? I've been giving it some deep thought, but haven't even had an idea worth trying yet.
Posted By: Jaeger

Re: Very confused... need advice... - 05/19/09 18:32

Hurray again! LOL! I fixed the engine bug, where the engine would not turn off after cranking up. You can now toggle the tank's engine on/off with the "e" key, and it won't move until the engine has went through the starting sequence (played entire cranking sound) and begins running.

What was causing this bug was the fact that I was using an external function to toggle the engine and make the entity play the sound. Furthermore, the tank's action has a loop "while(engine_state == 1) {...instructions...}. Once this loop is initiated, you have to give it the instructions again that are outside the loop, if you need them. I hope I make sense. An example of this same phenomena is the bug I was having with camera position. At first, my camera updates code was only given inside the tanks while(1) loop, and not the while(engine_state == 1) loop. So when I cranked the engine, camera updates no longer worked. I fixed that one by adding the same camera update code inside the engine_state loop.

The engine bug was fixed with the same concept, and by making the instructions to toggle the engine, play sounds, etc all inside the tanks action, as opposed to an external/global function. Also, I had to add a wait() instruction of 7 frames above the if(key_e) inside the while(1) loop. The wait is required because if it's not there, the instructions are executed so quickly that it cranks the engine again before you can even get your finger off the button. 7 frames was the shortest wait(7) that would work for me. However, it still wants you to press the key and release in abruptly. If you press it down really slow, the engine just restarts. But I don't see this as a real problem. Just about every professional game I've played behaves the same way.

Now, if I can just solve the physics dilemma of preventing the tank from moving/sliding along its y axis, I'll be pretty much done with the bare basics of this little project. laugh
© 2024 lite-C Forums