|
2 registered members (Grant, AndrewAMD),
911
guests, and 9
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Physics questions...
#266652
05/19/09 04:58
05/19/09 04:58
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
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: darkinferno]
#266665
05/19/09 06:13
05/19/09 06:13
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
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.
///////////////////////////////////////////////////////////////////////////////////////////////////
// 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
Expert
|
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: Jaeger]
#266684
05/19/09 07:29
05/19/09 07:29
|
Joined: May 2009
Posts: 258 Chicago
Jaeger
OP
Member
|
OP
Member
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.
|
|
|
|