Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Grant, AndrewAMD), 911 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Physics questions... #266652
05/19/09 04:58
05/19/09 04:58
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
I'm having some trouble with physics now, lol.

First of all, my tank entity has it's phent_type set to box, and I've defined the bounding box size, perfectly, per the positions of some invisible vertex's. I've hit F11 and viewed it, and it's just right.

Now the terrain's collision detection is per polygon, like I understand it should be. However, when the tank spawns into the level, it stops about 1-2 meters above the ground. And it just hangs there in mid-air, lol. I have no idea why it's doing this. Any ideas?

Also, if anyone can point me to a good tutorial about physics constraints, like setting up wheels, and even motors, I can definitely use it. I can't find any good info on it.

Re: Physics questions... [Re: Jaeger] #266655
05/19/09 05:39
05/19/09 05:39
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)
mp idea, maybe seeing the code would help, if u wanna show it but i bet its a minor problem

Re: Physics questions... [Re: darkinferno] #266665
05/19/09 06:13
05/19/09 06:13
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Here's the whole thing. I'm also having a problem with the toggle_engine function still. It switches the engine on, but not off, and when it runs, it allows the 0 key to free the camera, which it's not supposed to. What's weird was I changed the phent type to PH_POLY just to see what happened, and the camera bug went away. I have no idea why. I tried some other wierd things, and it would crash the program at runtime, and say the entity was not a physics object.

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 hnd_crank;

var hnd_tankidle;


// Defining sounds

SOUND* snd_crank = "crank.wav";

SOUND* snd_tankidle = "tank_01.wav";

//Declaring entity pointers

ENTITY* panzer;

ENTITY* tanktrackl;

ENTITY* tanktrackr;

// Defining movement vectors

VECTOR temp;

VECTOR vSpeed, vAngularSpeed, vForce, vMove, vAhead;

VECTOR coll_maxx;
VECTOR coll_minx;
VECTOR coll_maxy;
VECTOR coll_miny;
VECTOR coll_maxz;
VECTOR coll_minz;

VECTOR NULLVECTOR;



// Declaring funtions

function shiftskin();

function shiftskinr();

//////////////////////////////////////////////////////////////////////////////////////////////////
// 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_crank = ent_playsound(panzer, snd_crank, 95);
	   
	   wait(-3);
	   
   	hnd_tankidle = ent_playloop(panzer, snd_tankidle, 77);
   	
   		return(engine_state);
   	
   }

	//if engine is now off
	else
	{
   	snd_stop(hnd_tankidle);
   	
   		return(engine_state);
	}
	

	
}

// 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
   //phent_settype(me, PH_RIGID, PH_POLY);

}

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

// Tank movement code...

// Defining actions

// Tracks' actions

action left_track()
{
	
   set(my,PASSABLE);  
   
 	while (1)
 	{
 		vec_set(my.x,you.x); // place the track at the xyz position  of the entity who created it
 		
 		wait(1);
 	}
}

action right_track()
{  

	set(my,PASSABLE);  
 
 	while (1)
 	{
 		vec_set(my.x,you.x); // place the track at the xyz position  of the entity who created it
 		
 		wait(1);
 	}
}

// Panzer's action

action tank_controls()
{
	wait(1);
	
	me = panzer;
	
   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);
  


      // Scales bounding box to vector of vertices
      vec_for_vertex(coll_maxx, me, 25);
      vec_for_vertex(coll_minx, me, 21);
      
      vec_for_vertex(coll_maxy, me, 19);
      vec_for_vertex(coll_miny, me, 20);
      
      vec_for_vertex(coll_maxz, me, 24);
      vec_for_vertex(coll_minz, me, 26);
      
      wait(1);	// wait 1 frame after creation
      vec_set(my.max_x,coll_maxx);
      vec_set(my.min_x,coll_minx);
      
      vec_set(my.max_y, coll_maxy);
      vec_set(my.min_y, coll_miny);
      
      vec_set(my.max_z, coll_maxz);
      vec_set(my.min_z, coll_minz);
      
      c_setminmax(me);
      
   ent_create ("trk_left.mdl", NULLVECTOR, left_track);
	ent_create ("trk_right.mdl", NULLVECTOR, right_track);
     
   wait(3);  
      
	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);
      
      // E key toggles engine/on off, and changes var engine_state from 0 -> 1 and vice-versa...

      if(key_e)
      {
      
      	toggle_engine();
      	
      }
      
      while(engine_state == 1)
      {

      snd_tune (hnd_tankidle, 50, 30 + 100 * minv (key_cuu + key_cud + key_cul + key_cur, 1), 0);
      
      
      wait(1);
      }
 
      //   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
      }
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// 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));
   
   wait(2);
   // 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("pzIV7_ent_verts.mdl", vector(-225,-848,1500), tank_controls);
   
   wait(3);
   
}


Re: Physics questions... [Re: Jaeger] #266673
05/19/09 06:50
05/19/09 06:50
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Maybe ODE physics uses the vertice data, and not the min/max hull...

I've never had to do it this way, so I really don't know...


xXxGuitar511
- Programmer
Re: Physics questions... [Re: xXxGuitar511] #266676
05/19/09 06:59
05/19/09 06:59
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
If it was using the vertices, then the tank would sit flat on the ground like it should, lol. The vertices set the limits of the BB anyway. If I changed the phent type to sphere, it rolls around, looking rather silly, but the physics work like its a real sphere. However, this just doesn't work for some reason...

Re: Physics questions... [Re: Jaeger] #266684
05/19/09 07:29
05/19/09 07:29
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Well, my silly little test of changing the tank to ph_sphere exposed a problem. My tracks didn't follow the tank's movement. So I changed their actions to include the following lines:

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

Now the tracks stay perfectly mounted to the tank, regardless of its position. So at least I got something to work right, lol. About time, huh?

But as to why the tank floats 2 meters above the ground in any other phenttype, I have no clue. The bounding box is just right. It really doesn't make sense to me.

Oh... Could a model's origin have anything to do with its physics? I wouldn't think so, but just asking...

Last edited by Jaeger; 05/19/09 07:32.
Re: Physics questions... [Re: Jaeger] #266686
05/19/09 07:40
05/19/09 07:40
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
LOL! I changed the model's origin and now the physics are working... Well, they appear to be. I'm going to do a few more trials with this before I get too excited. If that was all that was causing my problem, I'm going to feel sooo silly...

Re: Physics questions... [Re: Jaeger] #266746
05/19/09 12:53
05/19/09 12:53
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Well, I've worked out a bunch of kinks and problems with this code. But now this is my question:

How do I ensure that phent_addcentralforce will only push my tank in the direction it's facing? Tanks don't slide sideways! LOL! I was able to push the tank around, just on the world's x axis. However, now I've introduced the ability to turn the tank, and when it turns, it pushes it sideways, still on the world's x axis.

I've tried using:

vec_rotate(vAhead,player.pan);

... and it doesn't work for some reason. Any tips?

Re: Physics questions... [Re: Jaeger] #266770
05/19/09 15:55
05/19/09 15:55
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

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


Moderated by  HeelX, Spirit 

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