High - Speed Turns....

Posted By: Matan_Golan1

High - Speed Turns.... - 07/26/05 16:26

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;


Posted By: Matan_Golan1

Re: High - Speed Turns.... - 07/27/05 13:03

what no one can help me??
Posted By: FoxHound

Re: High - Speed Turns.... - 07/27/05 14:30

The way real gears work.

A car engine cannot move the tires of a car from a dead stop at it's nomral power. So we reduce the gear ratio to help. 1:1 is normal, if we drop this to 2:1, the engine will turn two times for every time the wheel turns once. This means the car has twice the power, but will top out at a much lower high speed (the gears start much lower then this btw). For this reason we raise the ratio as the car builds up speed, and at high speed we can even go higher then 1:1 to help build up top speed or fuel economy.

Now that you know this you simply change the speed limit in phcon_setmotor (you used motor2 there) to a higher number as you change gear via script.

if(gear == 1)
{
motor2 = 20;
}
if(gear == 2)
{
motor2 = 30;
}

this should give you the idea
Posted By: Matan_Golan1

Re: High - Speed Turns.... - 07/27/05 16:35

yeha but in the game if i change to 5th gear the car can move in real life the car cant move in that gear.
you see if i script it that way:

if(gear == 1)
{
motor2 = 10
}
....
if(gear ==5)
{
motor2 = 50
}

i can start the engine in 5th gear and the car will go even beter...
its not like gear ratio you just get the motor more power...
i know all about car's i know how real gearbox and drivetrain work's but i cant manange that into the physics engine because the motor function just add amount of power.
i think that i will need to do a constant motor power and to build gear system that bypass the motor...
but i need to do more thinking....

but what about the other problem????
the rear wheels are messed up!!


BTW: Sorry for my english.
Posted By: Marco_Grubert

Re: High - Speed Turns.... - 07/27/05 20:01

Your approach looks correct, maybe you just need to lower the available torque for higher gears so that the car can't overcome friction in that case. If that does not work you could fake it by checking the current velocity and if it is below a certain value prevent the shift into a higher gear (or shift into a higher gear but clip the maximum velocity).
Posted By: Matan_Golan1

Re: High - Speed Turns.... - 07/27/05 23:03

Marco:

thanks for replaying
about the tourqe thats the all deal, if you add more tourqe the car will be faster if you decrease the tourqe the car will be slower...
in real life there is indirect connection between engine RPM to the wheel RPM...
first gear is more power less speed
and 5th gear is less power more speed.

using the physics engine its direct connection
1st gear less power less speed
5th gear more power more speed....

about the velocity thing....
i thought about it but this is my last choise...
Posted By: Marco_Grubert

Re: High - Speed Turns.... - 07/28/05 00:18

Quote:

about the tourqe thats the all deal, if you add more tourqe the car will be faster if you decrease the tourqe the car will be slower...
in real life there is indirect connection between engine RPM to the wheel RPM... first gear is more power less speed and 5th gear is less power more speed.




I can't quite follow you. What you refer to as power is effectively torque. In a car simulation we don't care about the power available from the engine, but the power delivered to the drivetrain (behind the gear box). Since the engine's power there is used to rotate the wheels you can ignore the engine power and only look at the torque at this point.

The first gear should provide high torque but only low speed, and the fifth gear should offer a high max. speed but very little torque.
Torque does _not_ in and of itself determine speed, it determines how much resistance the wheels can overcome. What determines speed in GameStudio is the speed value you set for that particular motor. Whether this desired speed can actually be achieved depends on the car's mass, friction, dampening and how much torque you allow to be applied.

What happens if you change your script (gear definitions) so that the torque values get lower and not higher as they are now ?
Posted By: FoxHound

Re: High - Speed Turns.... - 07/28/05 00:35

Basicaly What i meant on my reply is to make it act lke it is getting less power to the wheels. and to do this you simply stop it from going any faster at that point.

Hundered of things in your games will not be what they seem, this is game making.
Posted By: Matan_Golan1

Re: High - Speed Turns.... - 07/30/05 13:52

yeah but this is the problem if in 5th gear i would define low tourqe the car will go slower...(in the engine phyisics)
© 2024 lite-C Forums