Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 10/25/26 03:42
Chat Room for Zorro Programmers
by Haitao_Ren. 10/25/26 03:14
Trading Journey
by Haitao_Ren. 10/25/26 03:14
Algorithmic trading course with Zorro
by Haitao_Ren. 10/25/26 03:12
Zorro tutorial ideas?
by Haitao_Ren. 10/25/26 02:47
Zorro plugin for Hyperliquid.xyz
by mayarik. 10/24/26 09:14
Tradestation missing in table of contents
by AndrewAMD. 10/23/26 14:35
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (JeyKey II, alibaba), 7,856 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Haitao_Ren, JimSimons, julienp, julienper, KelleyAbbey
19247 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
vehicle physics #15498
05/03/03 21:39
05/03/03 21:39
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
...my current car script. use q,a,w,s to adjust the spring/damper values! use z/y,x if you have to flip the car (currently the car tends to flip over in narrow curves). if you have any ideas for improvements (or if you have a complete better script [Smile] ) please let us know!

code:
var video_mode = 9;
var video_depth = 32;

entity* p_player;
entity* p_FR_tyre;
entity* p_FL_tyre;
entity* p_RL_tyre;
entity* p_RR_tyre;

var d3d_alphadepth=32;
var d3d_shadowdepth=24;
var d3d_lightres=on;

var max_entities=1000;
var max_ph_entites=500;

var clip_size=0;

on_f12=_tog_dbg;

string mdl_car=<car.mdl>;
string mdl_tyre=<tyre_0.mdl>;

//-----------------------------------------------------------------------------move_camera_player
function move_camera_player()
{
camera.ambient=0;
camera.arc=60;

var cam_ang[3];
var cam_dist=1500;
cam_ang.pan=0;
cam_ang.tilt=70;
cam_ang.roll=0;


while(1)
{
if(mouse_right)
{
cam_ang.pan+=10*mouse_force.x;
cam_ang.tilt+=10*mouse_force.y;
cam_ang.tilt=min(max(cam_ang.tilt,5),70);
}
else
{
}

cam_dist-=mickey.z;
cam_dist=min(max(cam_dist,300),3000);

camera.x=p_player.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=p_player.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=p_player.z+sin(cam_ang.tilt)*cam_dist;
vec_set(temp,p_player.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);

wait(1);
}
}

var FR_wheel_ID;
var FL_wheel_ID;
var RL_wheel_ID;
var RR_wheel_ID;

var p1[3];
var p2[3];
var p3[3];
var p4[3];
var p5[3];
var p6[3];

var sc=1;
var dc=0.005;
//-----------------------------------------------------------------------------car setup
action FR_tyre
{
p_FR_tyre=my;
my.shadow=on;

phent_settype(my,PH_RIGID,PH_SPHERE);
phent_setgroup(my,2);
phent_setmass(my,10,PH_SPHERE);
phent_setfriction(my,80);
phent_setelasticity(my,50,10);
phent_setdamping(my,20,20);

vec_set(p2,vector(0,0,1));
vec_set(p3,vector(0,1,0));
vec_set(p4,vector(-40,40,0));
vec_set(p6,vector(sc,dc,0));
FR_wheel_ID=phcon_add(PH_WHEEL,p_player,my);
phcon_setparams1(FR_wheel_ID,my.x,p2,p3);
phcon_setparams2(FR_wheel_ID,p4,nullvector,p6);
}


action FL_tyre
{
p_FL_tyre=my;
my.shadow=on;
my.pan=180;

phent_settype(my,PH_RIGID,PH_SPHERE);
phent_setgroup(my,2);
phent_setmass(my,10,PH_SPHERE);
phent_setfriction(my,80);
phent_setelasticity(my,50,10);
phent_setdamping(my,20,20);

vec_set(p2,vector(0,0,1));
vec_set(p3,vector(0,1,0));
vec_set(p4,vector(-40,40,0));
vec_set(p6,vector(sc,dc,0));
FL_wheel_ID=phcon_add(PH_WHEEL,p_player,my);
phcon_setparams1(FL_wheel_ID,my.x,p2,p3);
phcon_setparams2(FL_wheel_ID,p4,nullvector,p6);
}


action RL_tyre
{
p_RL_tyre=my;
my.shadow=on;
my.pan=180;

phent_settype(my,PH_RIGID,PH_SPHERE);
phent_setgroup(my,2);
phent_setmass(my,10,PH_SPHERE);
phent_setfriction(my,90);
phent_setelasticity(my,50,10);
phent_setdamping(my,20,20);

vec_set(p2,vector(0,0,1));
vec_set(p3,vector(0,1,0));
vec_set(p4,vector(0,0,0));
vec_set(p6,vector(sc,dc,0));
RL_wheel_ID=phcon_add(PH_WHEEL,p_player,my);
phcon_setparams1(RL_wheel_ID,my.x,p2,p3);
phcon_setparams2(RL_wheel_ID,p4,nullvector,p6);
}

action RR_tyre
{
p_RR_tyre=my;
my.shadow=on;

phent_settype(my,PH_RIGID,PH_SPHERE);
phent_setgroup(my,2);
phent_setmass(my,10,PH_SPHERE);
phent_setfriction(my,90);
phent_setelasticity(my,50,10);
phent_setdamping(my,20,20);

vec_set(p2,vector(0,0,1));
vec_set(p3,vector(0,1,0));
vec_set(p4,vector(0,0,0));
vec_set(p6,vector(sc,dc,0));
RR_wheel_ID=phcon_add(PH_WHEEL,p_player,my);
phcon_setparams1(RR_wheel_ID,my.x,p2,p3);
phcon_setparams2(RR_wheel_ID,p4,nullvector,p6);
}

action car
{
p_player=my;
wait(1);
my.shadow=on;
my.material=mat_metal;

phent_settype(my,PH_RIGID,PH_BOX);
phent_setgroup(my,2);
phent_setmass(my,160,PH_BOX);
phent_setfriction(my,40);
phent_setelasticity(my,50,10);
phent_setdamping(my,20,20);

vec_for_vertex(temp,my,306);
ent_create(mdl_tyre,temp,FR_tyre);

vec_for_vertex(temp,my,36);
ent_create(mdl_tyre,temp,FL_tyre);

vec_for_vertex(temp,my,5);
ent_create(mdl_tyre,temp,RL_tyre);

vec_for_vertex(temp,my,304);
ent_create(mdl_tyre,temp,RR_tyre);
}

//--------------------------------------------------------------------------------control
function control()
{
var m1_1[3];
var m1_2[3];
var m2[3];
var wheel_target=0;
while(1)
{
if(key_cul)
{
wheel_target=-38;
}
if(key_cur)
{
wheel_target=38;
}
if((!key_cul&&!key_cur)||(key_cul&&key_cur))
{
wheel_target=0;
}
if(key_cuu)
{
vec_set(m2,vector(-50,500,0));
}
if(key_cud)
{
vec_set(m2,vector(0,500,0));
}
if((!key_cuu&&!key_cud)||(key_cuu&&key_cud))
{
vec_set(m2,vector(0,0,0));
}

phcon_getposition(FR_wheel_ID,temp);
vec_set(m1_1,vector((wheel_target-temp.x)*0.2,500,0));

phcon_getposition(FL_wheel_ID,temp);
vec_set(m1_2,vector((wheel_target-temp.x)*0.2,500,0));

phcon_setmotor(FR_wheel_ID,m1_1,m2,nullvector);
phcon_setmotor(FL_wheel_ID,m1_2,m2,nullvector);
phcon_setmotor(RR_wheel_ID,nullvector,m2,nullvector);
phcon_setmotor(RL_wheel_ID,nullvector,m2,nullvector);

wait(1);
}
}

string s1;
string s2;
//--------------------------------------------------------------------------------debug
function debug()
{
while(1)
{
str_cpy(s1,"sc: ");
str_for_num(s2,sc);
str_cat(s1,s2);
draw_text(s1,20,100,vector(255,255,255));
str_cpy(s1,"dc: ");
str_for_num(s2,dc);
str_cat(s1,s2);
draw_text(s1,20,124,vector(255,255,255));
wait(1);
}
}

//--------------------------------------------------------------------------------set_scdc
function set_scdc()
{
vec_set(p6,vector(sc,dc,0));
phcon_setparams2(FR_wheel_ID,vector(-40,40,0),nullvector,p6);
phcon_setparams2(FL_wheel_ID,vector(-40,40,0),nullvector,p6);
phcon_setparams2(RL_wheel_ID,nullvector,nullvector,p6);
phcon_setparams2(RR_wheel_ID,nullvector,nullvector,p6);
}
function inc_sc()
{
while(key_q)
{
sc+=0.001;
sc=min(max(sc,0),100);
set_scdc();
wait(1);
}
}
function dec_sc()
{
while(key_a)
{
sc-=0.001;
sc=min(max(sc,0),100);
set_scdc();
wait(1);
}
}
function inc_dc()
{
while(key_w)
{
dc+=0.001;
dc=min(max(dc,0),100);
set_scdc();
wait(1);
}
}
function dec_dc()
{
while(key_s)
{
dc-=0.001;
dc=min(max(dc,0),100);
set_scdc();
wait(1);
}
}
on_q=inc_sc;
on_a=dec_sc;
on_w=inc_dc;
on_s=dec_dc;

//--------------------------------------------------------------------------------flip
function flipl()
{
phent_addtorquelocal(p_player,vector(-100000,0,0));
}

function flipr()
{
phent_addtorquelocal(p_player,vector(100000,0,0));
}

on_z=flipl;
on_x=flipr;

//--------------------------------------------------------------------------------initialize_physics
function initialize_physics
{
ph_setgravity(vector(0,0,-380));
ph_setcorrections(20000,0.1);
}

//--------------------------------------------------------------------------------main
function main()
{
level_load("physics_test.wmb");
wait(1);

sun_angle.pan=210;
sun_angle.tilt=25;

camera.clip_near=50;
camera.clip_far=50000;
camera.arc=75;

ent_create(mdl_car,vector(0,0,200),car);
initialize_physics();

while(p_player==null){wait(1);}
move_camera_player();
control();
debug();
}



Re: vehicle physics #15499
05/03/03 21:49
05/03/03 21:49
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
i suspect the tendency to flip over is caused by the spherical hull used for the wheels. the spheres make it easy to roll over for the car. maybe this gets better once we can use the cylindrical hulls?

Re: vehicle physics #15500
05/03/03 22:03
05/03/03 22:03
Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
Phantom88 Offline
Expert
Phantom88  Offline
Expert

Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
quote:
Originally posted by ventilator:
(currently the car tends to flip over in narrow curves). if you have any ideas for improvements (or if you have a complete better script [Smile] ) please let us know!

How about: my.scale_z=.5;
[Big Grin] It surely will not flip over anymore [Big Grin]
My car doesn't flip over, but it is only a simple cube, with scale_z low, and scale_y high...
Thanks for the script...

~Phantom88~


Programmer, Gamer ICQ #: 157485106 | Xfire: Phantom1988 | MSN: lauri_andler@hotmail.com | AIM: FinPhantom | YAHOO: FinPhantom
Re: vehicle physics #15501
05/03/03 22:15
05/03/03 22:15
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
if you go into a curve full speed it's noticable that the rear wheels bend outwards if you look very closely. this could also cause the flipping tendency... i thought i constrained them to not do that! do the spring/damper constants also make the rear wheels' (0,0,1) axis more loose?

<edit>no, the spring/damper constants don't seem to have anything to do with it... marco, is this the reason for suggesting to use hinge instead of wheel constraints for the rear wheels?</edit>

@phantom88: you are right! maybe the visible chassis should be different from the physics chassis so that the center of gravity is lower...

Re: vehicle physics #15502
05/03/03 23:11
05/03/03 23:11
Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
Phantom88 Offline
Expert
Phantom88  Offline
Expert

Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
quote:
Originally posted by ventilator:

@phantom88: you are right! maybe the visible chassis should be different from the physics chassis so that the center of gravity is lower...

Good idea, might work, but what about the Collision detection! It would then also use the smaller chassis, and the visible one would go through the floor...

~Phantom88~


Programmer, Gamer ICQ #: 157485106 | Xfire: Phantom1988 | MSN: lauri_andler@hotmail.com | AIM: FinPhantom | YAHOO: FinPhantom
Re: vehicle physics #15503
05/04/03 20:43
05/04/03 20:43

A
Anonymous
Unregistered
Anonymous
Unregistered
A



I'm just curious would this work with a horse? Like if someone was on a horse?

Re: vehicle physics #15504
05/05/03 00:30
05/05/03 00:30
Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
Phantom88 Offline
Expert
Phantom88  Offline
Expert

Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
@Greenknight: How do you apply the physics of a car to a horse? [Wink]

~Phantom88~


Programmer, Gamer ICQ #: 157485106 | Xfire: Phantom1988 | MSN: lauri_andler@hotmail.com | AIM: FinPhantom | YAHOO: FinPhantom
Re: vehicle physics #15505
05/05/03 13:28
05/05/03 13:28

A
Anonymous
Unregistered
Anonymous
Unregistered
A



The code looks interesting, cant wait until my A6 upgrade gets here to try it.

(hehe...horse power)

Re: vehicle physics #15506
05/06/03 02:37
05/06/03 02:37

A
Anonymous
Unregistered
Anonymous
Unregistered
A



quote:
Originally posted by ventilator:
<edit>no, the spring/damper constants don't seem to have anything to do with it... marco, is this the reason for suggesting to use hinge instead of wheel constraints for the rear wheels?</edit>

Using hinges should make it more robust, but this wheel bending is a known problem and I do not have a fix for it (see FAQ section in physics manual).

Re: vehicle physics #15507
05/06/03 02:58
05/06/03 02:58
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
it doesn't get "bent out of shape" it just rotates a little around axis (0,0,1) although it shouldn't. is this the same problem like the one mentioned in the faq?

Page 1 of 3 1 2 3

Moderated by  HeelX, Spirit 

Gamestudio download | 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