hi....
im finally solve my last problem with the physics engine (car movement)
but now there is another one.
at high speeds the rear wheels are moving and it getting me to lose control about the car...
here is my script...

BTW:
if some one have an idea to make a useful gear change with the physics engine let me know about it.

Code:
 


//Car Physics Demo:
//Non-Public
//Writed by Matan Golan

//Starting Var's:
string level_str = <car_level.WMB>;
var video_mode = 8;
var video_screen = 2;
var d3d_lightres = on;
var velochk;
var realvelo;

string str_fwd = "Forward Wheel Drive";
string str_rwd = "Rear Wheel Drive";
string str_awd = "All Wheel Drive (4X4)";
//Panel Fonts:
font digit_font = "arial",1,20;
font text_font = "arial",1,40;



//Game Pre-Defines:

//Entity's:
entity* car;
entity* fr_wheel;
entity* fl_wheel;
entity* rr_wheel;
entity* rl_wheel;

//Gravity:
var gravity[3] = 0,0,-380;

//Strings:
string tire_mdl = "tire.mdl";
string car_mdl = "car.mdl";

//Tire:
var tire_elastic = 1;
var tire_fric = 120;
var tire_mass = 130;
var tire_min_speed = 7;

//Car Body:
var car_elastic = 1;
var car_firc = 40;
var car_mass = 130;
var car_min_speed = 5;

//Con's ID'S:
var fr_wheel_id;
var fl_wheel_id;
var rr_wheel_id;
var rl_wheel_id;

//Con's Param's:
var parm1[3];
var parm2[3];
var parm3[3];
var parm4[3];
var parm5[3];
var parm6[3];

//Movement Var's:
var motor1a[3];
var motor1b[3];
var ranglea[3];
var rangleb[3];
var motor2[3];
var wheel_angle;
var drive_mode = 1;

//Gear Var's:
var gear_num;
var 1st_gear[3] = 5000,1000,0;
var 2nd_gear[3] = 1600,1500,0;
var 3rd_gear[3] = 1200,1800,0;
var 4th_gear[3] = 1000,2200,0;
var 5th_gear[3] = 820,2500,0;
var rev_gear[3] = -1000,800,0;
var N_gear[3] = 2000,2000,0;

//Information Panel:
panel video_memory
{
pos_x = 0; pos_y = 0;
digits = 0, 0, 5, digit_font, 1,d3d_texskins; //Level models
digits = 0,20, 5, digit_font, 1,d3d_texsurfs; //Surface
digits = 0,40, 5, digit_font, 1,d3d_texsmaps; //shadows
digits = 0,60, 5, digit_font, 1,d3d_texbmaps; //bmaps
digits = 0,100,5,digit_font, 1, gear_num;
flags = VISIBLE;
}

text FWD{
layer = 5;
pos_x = 60;
size_y = 40;
offset_y = 0;
font = text_font;
string = str_fwd;
alpha = 100;
flags = center_x,center_y, narrow, transparent;
}

text AWD{
layer = 5;
pos_x = 60;
size_y = 40;
offset_y = 0;
font = text_font;
string = str_awd;
alpha = 100;
flags = center_x,center_y, narrow, transparent;
}

text RWD{
layer = 5;
pos_x = 60;
size_y = 40;
offset_y = 0;
font = text_font;
string = str_rwd;
alpha = 100;
flags = center_x,center_y, narrow, transparent;
}


action car_body
{
my.pan += 180;

car = my;

car.ambient = 50;



phent_settype(my,ph_rigid,ph_poly);
phent_setgroup(my,2);
phent_setmass(my,car_mass,ph_poly);
phent_setfriction(my,car_firc);
phent_setelasticity(my,car_elastic,car_min_speed);

}

action car_fl_wheel
{
my.pan -= 90;

fl_wheel = my;

phent_settype(my,ph_rigid,ph_sphere);
phent_setgroup(my,2);
phent_setmass(my,tire_mass,ph_sphere);
phent_setfriction(my,tire_fric);
phent_setelasticity(my,tire_elastic,tire_min_speed);
phent_setdamping(my,50,50);

vec_set(parm2,vector(0,0,1));
vec_set(parm3,vector(0,1,0));
vec_set(parm4,vector(-40,40,0));
vec_set(parm6,vector(0,0,0));

fl_wheel_id = phcon_add(ph_wheel,car,my);

phcon_setparams1(fl_wheel_id,my.x,parm2,parm3);
phcon_setparams2(fl_wheel_id,parm4,nullvector,parm6);
}

action car_fr_wheel
{
my.pan -= 90;

fr_wheel = my;

phent_settype(my,ph_rigid,ph_sphere);
phent_setgroup(my,2);
phent_setmass(my,tire_mass,ph_sphere);
phent_setfriction(my,tire_fric);
phent_setdamping(my,50,50);
phent_setelasticity(my,tire_elastic,tire_min_speed);

vec_set(parm2,vector(0,0,1));
vec_set(parm3,vector(0,1,0));
vec_set(parm4,vector(-40,40,0));
vec_set(parm6,vector(0,0,0));

fr_wheel_id = phcon_add(ph_wheel,car,my);

phcon_setparams1(fr_wheel_id,my.x,parm2,parm3);
phcon_setparams2(fr_wheel_id,parm4,nullvector,parm6);
}

action car_rr_wheel
{
my.pan -= 90;

rr_wheel = my;

phent_settype(my,ph_rigid,ph_sphere);
phent_setgroup(my,2);
phent_setmass(my,tire_mass,ph_sphere);
phent_setfriction(my,tire_fric);
phent_setdamping(my,50,50);
phent_setelasticity(my,tire_elastic,tire_min_speed);

vec_set(parm2,vector(0,0,1));
vec_set(parm3,vector(0,1,0));
vec_set(parm4,vector(0,0,0));
vec_set(parm6,vector(0,0,0));

rr_wheel_id = phcon_add(ph_wheel,car,my);

phcon_setparams1(rr_wheel_id,my.x,parm2,parm3);
phcon_setparams2(rr_wheel_id,parm4,nullvector,parm6);
}

action car_rl_wheel
{
my.pan -= 90;

rl_wheel = my;

phent_settype(my,ph_rigid,ph_sphere);
phent_setgroup(my,2);
phent_setmass(my,tire_mass,ph_sphere);
phent_setfriction(my,tire_fric);
phent_setdamping(my,50,50);
phent_setelasticity(my,tire_elastic,tire_min_speed);

vec_set(parm2,vector(0,0,1));
vec_set(parm3,vector(0,1,0));
vec_set(parm4,vector(0,0,0));
vec_set(parm6,vector(0,0,0));

rl_wheel_id = phcon_add(ph_wheel,car,my);

phcon_setparams1(rl_wheel_id,my.x,parm2,parm3);
phcon_setparams2(rl_wheel_id,parm4,nullvector,parm6);
}


function get_car_control()
{
while(1)
{

if(key_cuu == 1)
{
if(gear_num == 1)
{
vec_set(motor2,1st_gear);
}
if(gear_num == 2)
{
vec_set(motor2,2nd_gear);
}
if(gear_num == 3)
{
vec_set(motor2,3rd_gear);
}
if(gear_num == 4)
{
vec_set(motor2,4th_gear);
}
if(gear_num == 5)
{
vec_set(motor2,5th_gear);
}
if(gear_num == -1)
{
vec_set(motor2,rev_gear);
}
if(gear_num == 0)
{
vec_set(motor2,nullvector);
}

}

if(key_c == 1) //cluth
{
vec_set(motor2,nullvector);
if(key_q == 1)
{
gear_num += 1;
key_q = 0;
sleep(0.3);
if(gear_num >= 5)
{
gear_num = 5;
}
}
if(key_z == 1)
{
gear_num -= 1;
key_z = 0;
sleep(0.3);
if(gear_num <=-1)
{
gear_num = -1;
}
}
}

if(key_cud ==1)
{
phent_setdamping(fr_wheel,80,80);
phent_setdamping(fl_wheel,80,80);
phent_setdamping(rr_wheel,80,80);
phent_setdamping(rl_wheel,80,80);

}

if(key_cud == 0)
{
phent_setdamping(fr_wheel,30,30);
phent_setdamping(fl_wheel,30,30);
phent_setdamping(rr_wheel,30,30);
phent_setdamping(rl_wheel,30,30);
}

if(key_cuu == 1 && key_cud == 1) || (key_cuu == 0 && key_cud == 0)
{
vec_set(motor2,vector(0,0,0));
}


if(key_cul == 1)
{
wheel_angle = -30;
}

if(key_cur == 1)
{
wheel_angle = 30;
}

if(key_cur == 1 && key_cul == 1) || (key_cur == 0 && key_cul == 0)
{
wheel_angle = 0;
}

if(key_1)
{
drive_mode = 1;
}

if(key_2)
{
drive_mode = 2;
}

if(key_3)
{
drive_mode= 3;
}

phcon_getposition(fr_wheel_id,temp);
vec_set(motor1b,vector((wheel_angle-temp.x)*0.2,500,0));

phcon_getposition(fl_wheel_id,temp);
vec_set(motor1a,vector((wheel_angle-temp.x)*0.2,500,0));

phcon_getposition(rl_wheel_id,temp);
vec_set(ranglea,vector (temp.x,temp.y,temp.z));

phcon_getposition(rr_wheel_id,temp);
vec_set(rangleb,vector (temp.x,temp.y,temp.z));

if(drive_mode == 1)//FWD:
{
phcon_setmotor(fl_wheel_id,motor1a,motor2,nullvector);
phcon_setmotor(fr_wheel_id,motor1b,motor2,nullvector);
phcon_setmotor(rl_wheel_id,ranglea,nullvector,nullvector);
phcon_setmotor(rr_wheel_id,rangleb,nullvector,nullvector);

FWD.visible = on;
AWD.visible = off;
RWD.visible = off;

}

if(drive_mode == 2)//RWD:
{
phcon_setmotor(fl_wheel_id,motor1a,nullvector,nullvector);
phcon_setmotor(fr_wheel_id,motor1b,nullvector,nullvector);
phcon_setmotor(rl_wheel_id,ranglea,motor2,nullvector);
phcon_setmotor(rr_wheel_id,rangleb,motor2,nullvector);
RWD.visible = on;
AWD.visible = off;
FWD.visible = off;
}

if(drive_mode == 3)//AWD:
{
phcon_setmotor(fl_wheel_id,motor1a,motor2,nullvector);
phcon_setmotor(fr_wheel_id,motor1b,motor2,nullvector);
phcon_setmotor(rl_wheel_id,ranglea,motor2,nullvector);
phcon_setmotor(rr_wheel_id,rangleb,motor2,nullvector);
AWD.visible = on;
RWD.visible = off;
FWD.visible = off;

}



wait(1);
}
}

action Need_Me
{
phent_settype(my,PH_RIGID,PH_sphere);
phent_setgroup(my,2);
phent_setmass(my,tire_mass,PH_box);
}

function create_game()
{
ph_setgravity(vector(0,0,-380));
ph_setcorrections(30000,0.05);

car = ent_create("car.mdl", vector(0,0,50), car_body);

vec_for_vertex(temp,car,306);
fr_wheel = ent_create("tire.mdl",temp,car_fr_wheel);

vec_for_vertex(temp,car,36);
fl_wheel = ent_create("tire.mdl",temp,car_fl_wheel);

vec_for_vertex(temp,car,304);
rl_wheel = ent_create("tire.mdl",temp,car_rl_wheel);

vec_for_vertex(temp,car,5);
rr_wheel = ent_create("tire.mdl",temp,car_rr_wheel);


rr_wheel = ent_create("tire.mdl",vector(0,0,-2000),Need_Me);
}

function get_velo()
{
phent_getvelocity(fl_wheel,velochk,nullvector);
realvelo = (velochk/0.245);
}

function main_quit()
{
exit;
}


function camera_control()
{
while(1)
{

camera.x = car.x - 300 * cos(car.pan);
camera.y = car.y - 300 * sin(car.pan) ;
camera.z = car.z + 100;
camera.pan = car.pan;
camera.tilt = -20;

wait(1);
}
}


//Main Starting Function:
function main()
{
level_load(level_str);
wait(3);
clip_size = 1;
d3d_anisotropy = 5;
d3d_mipmapping = 3;
d3d_shadowdepth = 24;

camera_control(); // get camera control by WASD

create_game();
get_car_control();
}


on_F9 = _sshot;



Last edited by Matan_Golan1; 07/26/05 16:28.