Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Ayumi, AndrewAMD, Quad), 1,014 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 4 1 2 3 4
Very confused... need advice... #266388
05/17/09 20:48
05/17/09 20:48
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
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...

Re: Very confused... need advice... [Re: Jaeger] #266389
05/17/09 20:58
05/17/09 20:58
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
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

Re: Very confused... need advice... [Re: Jaeger] #266391
05/17/09 21:14
05/17/09 21:14
Joined: May 2008
Posts: 331
Lithuania, Vilnius
Jaxas Offline
Senior Member
Jaxas  Offline
Senior Member

Joined: May 2008
Posts: 331
Lithuania, Vilnius
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


The smaller the bug, the harder it is to kill.
_________________________________________
Forklift DEMO (3dgs)
Re: Very confused... need advice... [Re: Jaxas] #266394
05/17/09 21:38
05/17/09 21:38
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline
Serious User
darkinferno  Offline
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
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

Re: Very confused... need advice... [Re: Jaxas] #266395
05/17/09 21:39
05/17/09 21:39
Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
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);
     }
}



3333333333
Re: Very confused... need advice... [Re: Quad] #266399
05/17/09 22:05
05/17/09 22:05
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
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

Last edited by Jaeger; 05/17/09 22:25.
Re: Very confused... need advice... [Re: Jaeger] #266405
05/17/09 22:26
05/17/09 22:26
Joined: Feb 2008
Posts: 69
Australia
M
MegaMarioDeluxe Offline
Junior Member
MegaMarioDeluxe  Offline
Junior Member
M

Joined: Feb 2008
Posts: 69
Australia
If you want types to move, you could animate them in MED...


----
MegaMario
Regular 3D Game Studio User
http://www.krystalgaming.net
Re: Very confused... need advice... [Re: MegaMarioDeluxe] #266408
05/17/09 22:32
05/17/09 22:32
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
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.

Re: Very confused... need advice... [Re: Jaeger] #266416
05/17/09 23:02
05/17/09 23:02
Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
Ä°stanbul, Turkey
the example of moving uvs is applied on the bulldozer demo, it does what you just need.


3333333333
Re: Very confused... need advice... [Re: Quad] #266420
05/17/09 23:21
05/17/09 23:21
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
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...

Page 1 of 4 1 2 3 4

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1