Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
CAR PHYSICS FOLLOWING PATH #412801
12/03/12 12:19
12/03/12 12:19
Joined: Aug 2007
Posts: 49
Rio Claro, São Paulo, Brazil
C
Cristiano_Iost Offline OP
Newbie
Cristiano_Iost  Offline OP
Newbie
C

Joined: Aug 2007
Posts: 49
Rio Claro, São Paulo, Brazil
How can I make the car follow a path, using physics ? The variable that controls the angle of the whell is max_angle, but I can not make the wheels follow the path. I tried using vec_set, and vec_diff vec_to_angle but I can not at all.

The code is:

function wheel_physics_init()
{
entroda = my;
set (my, SHADOW);
my.emask |= ENABLE_ENTITY | ENABLE_IMPACT | ENABLE_FRICTION | ENABLE_BLOCK;
phent_settype (my, PH_RIGID, PH_SPHERE);
phent_setmass (my, 30, PH_SPHERE);
phent_setgroup (my, 2);
phent_setfriction (my, 100);
phent_setdamping (my, 20, 20);
phent_setelasticity (my, 0, 100);


}


// front wheels

function front_tyre_left()
{
wheel_physics_init();
my.emask |= ENABLE_ENTITY | ENABLE_IMPACT | ENABLE_FRICTION | ENABLE_BLOCK;
constr_front_left = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_front_left, my.x, vector (0,0,1), nullvector);
phcon_setparams2 (constr_front_left, nullvector, nullvector, nullvector);


}

function front_tyre_right()
{
entroda = my;
wheel_physics_init();
//my.emask |= ENABLE_ENTITY | ENABLE_IMPACT | ENABLE_FRICTION | ENABLE_BLOCK;
constr_front_right = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_front_right, my.x, vector (0,0,1), nullvector);
phcon_setparams2 (constr_front_right, nullvector, nullvector, nullvector);


}


// rear wheels

function back_tyre_left()
{
wheel_physics_init();
constr_back_left = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_back_left, my.x, nullvector, vector (0,1,0));
phcon_setparams2 (constr_back_left, nullvector, nullvector, nullvector);
}


function back_tyre_right()
{
wheel_physics_init();
constr_back_right = phcon_add (PH_WHEEL, chassis, my);
phcon_setparams1 (constr_back_right, my.x, nullvector, vector (0,1,0));
phcon_setparams2 (constr_back_right, nullvector, nullvector, nullvector);
}



function chassis_init()
{
var LastPos[3];
var Dir[3];
chassis = my;
set (chassis, SHADOW);
//init physics variables
phent_settype (chassis, PH_RIGID, PH_BOX); // rigid and box as collision hull
phent_setmass (chassis, 1, PH_BOX); // lighter than wheels to avoid tilt
phent_setgroup (chassis, 2); // all parts of the car in one group --> no collision
phent_setfriction (chassis, 100);
phent_setdamping (chassis, 0, 0);
phent_setelasticity (chassis, 20, 20); // only little bouncing

//init car wheels

//back

ent_create ("car_tyre_left.mdl", vector (chassis.x + 65, chassis.y - 45, chassis.z - 20), front_tyre_left);
ent_create ("car_tyre_right.mdl", vector (chassis.x + 65, chassis.y + 45, chassis.z - 20), front_tyre_right);

//front

ent_create ("car_tyre_left.mdl", vector (chassis.x - 65, chassis.y - 45, chassis.z - 20), back_tyre_left);
ent_create ("car_tyre_right.mdl", vector (chassis.x - 65, chassis.y + 45, chassis.z - 20), back_tyre_right);

wait(1);

while(1)
{

//if (key_a) stear_contr = - 60 * time_step;
//if (key_d) stear_contr = 60 * time_step;

stear_contr = (key_d - key_a);
max_angle += stear_contr * 10 * time_step;
max_angle = clamp (max_angle, -30, 30);

if (stear_contr != 0)
{
phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
}
else
{
max_angle = max_angle * (1 - (0.25 * time_step));
if (abs(max_angle) < 1)
max_angle = 0;
phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
}

// speed control
speed_contr = (key_w - key_s);//w = 1, s = -1, w & s = 0
//speed_contr = 1 * time_step;
ang_force = speed_contr * 1000 * time_step;

phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);
phcon_setmotor (constr_back_right, nullvector, vector(-ang_force, max_speed, 0), nullvector);

car_cam();


wait(1);
}

}

Last edited by Cristiano_Iost; 12/03/12 12:20.
Re: CAR PHYSICS FOLLOWING PATH [Re: Cristiano_Iost] #413043
12/06/12 20:39
12/06/12 20:39
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
is this the code that turns to follow path?
im not sure ,pretty new to using the car physics but thought i would
answer because this would be intresting to get into ...

max_angle = max_angle * (1 - (0.25 * time_step));
if (abs(max_angle) < 1)
max_angle = 0;
phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
}

not tested or attempted to do this but does this code not hamper your
other turning code

stear_contr = (key_d - key_a);
max_angle += stear_contr * 10 * time_step;
max_angle = clamp (max_angle, -30, 30);

which perhaps results in
max_angle+=0*10*time_step;


Compulsive compiler

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