converted physX car

Posted By: Random

converted physX car - 05/03/11 19:47

I converted a physical car (it was ode) to physX.
Someewere I read a few times that some peapol would like to see that script converted.
So if anybody needs it;

Click to reveal..
var constr_front_left;
var constr_front_right;

var constr_back_left;
var constr_back_right;

VECTOR mom_speed;
var max_angle;
var stear_contr;

var max_speed = 1500;
var ang_force;
var speed_contr;

ENTITY* chassis;

function wheel_physics_init()
{
set (my, SHADOW);
pXent_settype (my, PH_RIGID, PH_SPHERE);
pXent_setmass (my, 30, PH_SPHERE);
pXent_setgroup (my, 2);
pXent_setfriction (my, 100);
pXent_setdamping (my, 20, 20);
pXent_setelasticity (my, 0, 100);
}

function front_tyre_left()
{
wheel_physics_init();
pXcon_add(PH_WHEEL, chassis, my);
pXcon_setparams1 (constr_front_left, my.x, vector (0,0,1), nullvector);
pXcon_setparams2 (constr_front_left, nullvector, nullvector, nullvector);
}

function front_tyre_right()
{
wheel_physics_init();
pXcon_add(PH_WHEEL, chassis, my);
pXcon_setparams1 (constr_front_right, my.x, vector (0,0,1), nullvector);
pXcon_setparams2 (constr_front_right, nullvector, nullvector, nullvector);
}

function back_tyre_left()
{
wheel_physics_init();
pXcon_add(PH_WHEEL, chassis, my);
pXcon_setparams1 (constr_back_left, my.x, vector (0,0,1), nullvector);
pXcon_setparams2 (constr_back_left, nullvector, nullvector, nullvector);
}

function back_tyre_right()
{
wheel_physics_init();
pXcon_add(PH_WHEEL, chassis, my);
pXcon_setparams1 (constr_back_right, my.x, vector (0,0,1), nullvector);
pXcon_setparams2 (constr_back_right, nullvector, nullvector, nullvector);
}

action chassis()
{
my.armor = 100;
chassis = my;
set (chassis, SHADOW);

pXent_settype (chassis, PH_RIGID, PH_BOX);
pXent_setmass (chassis, 15, PH_BOX);
pXent_setgroup (chassis, 2);

pXent_setfriction (chassis, 20);
pXent_setdamping (chassis, 5, 5);
pXent_setelasticity (chassis, 10, 100);

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);
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);
while(my.armor>0)
{
stear_contr = (key_d - key_a);
max_angle += stear_contr * 3 * time_step;
max_angle = clamp (max_angle, -30, 30);
if (stear_contr != 0)
{
pXcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
pXcon_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;
pXcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
pXcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));
}
speed_contr = (key_w - key_s);//w = 1, s = -1, w & s = 0
ang_force = speed_contr * 1000 * time_step;

pXcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);
pXcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);

camera.x = chassis.x - 250 * cos(chassis.pan);
camera.y = chassis.y - 250 * sin(chassis.pan);
camera.pan = chassis.pan;
camera.z = chassis.z + 50;
camera.tilt = -15;

wait(1);
}
}


Random
Posted By: jweb

Re: converted physX car - 05/12/11 16:32

Hi Random

Thanks for this work.

I see pXcon_setmotor is new ab Version 8.12. This is a good News.
I work with 8.10.
Which Version a you use for coding this Sample ?

THX
JW
Posted By: Random

Re: converted physX car - 05/14/11 13:44

3d gamestudio commercial 8.10

I hope it helps
Posted By: Progger

Re: converted physX car - 05/14/11 15:16

but there is something wrong which also was wron in the other version

in this lines

instead of

Code:
pXcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);
pXcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);




this


pXcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);
pXcon_setmotor (constr_back_right, nullvector, vector(-ang_force, max_speed, 0), nullvector);
Posted By: Random

Re: converted physX car - 05/16/11 13:25

ups, sorry grin
Posted By: Progger

Re: converted physX car - 05/24/11 20:08

Well its a little old but this version doesnt work.Did you test it or you though no mistakes and then put in inside here?
The parameters are wrong and you gave an action the same name as an Entity well totally buggy
Posted By: jweb

Re: converted physX car - 05/25/11 20:55

yes the code doesent work for me to.
Posted By: Progger

Re: converted physX car - 05/27/11 16:13

Php Code:
#include <default.c>
#include <acknex.h>
#include <ackphysx.h>

function mass ()
{
	pXent_setmass(my,60);
	pXent_setfriction (my, 100);
	pXent_setdamping (my, 20, 20);
	pXent_setelasticity (my,20);
   //pXent_addforcecentral (my,vector(0,0,2000));
}


function simple_car()
{
	ENTITY* car = ent_create("bmw.mdl",vector(300,-1000,5),NULL); 
	pXent_settype(car,PH_RIGID,PH_BOX);
	pXent_setmass(car,30);
	ENTITY* BLwheel = ent_create("bmwwheel.mdl",vector(car.x-50,car.y-24,car.z-12),mass);
	ENTITY* BRwheel = ent_create("bmwwheel.mdl",vector(car.x-50,car.y+24,car.z-12),mass);
	ENTITY* FLwheel = ent_create("bmwwheel.mdl",vector(car.x+56,car.y-24,car.z-12),mass);
	ENTITY* FRwheel = ent_create("bmwwheel.mdl",vector(car.x+56,car.y+24,car.z-12),mass);
	pXcon_add ( PH_WHEEL, FLwheel, car, 0 );
	pXcon_add ( PH_WHEEL, FRwheel, car, 0 );
	pXcon_add ( PH_WHEEL, BLwheel, car, 0 );
	pXcon_add ( PH_WHEEL, BRwheel, car, 0 );
	//drive the car		
	while(1)
	{
		speed=clamp(speed,-2000,2000);
		lenk=clamp(lenk,-20,20);
		
		if(key_w)
		{
			speed-=100;
		}
		else
		if(key_w==0)
		speed+=10;
		
		if(key_s)
		{
			speed+=100;
		}
		
		if(key_a)
		{
			lenk-=2;
		}
		
		if(key_d)
		{
			lenk+=2;
		}
		
		DEBUG_VAR(lenk,200);
		pXcon_setwheel (FLwheel,lenk,0,0);
		pXcon_setwheel (FRwheel,lenk,0,0); // steer to the right
		pXcon_setwheel (BLwheel,0,speed,0);
		pXcon_setwheel (BRwheel,0,speed,0);
		
 
		
		
		//	var max_speed = 3000;
		//	 var speed_contr =5*(key_w - key_s);//w = 1, s = -1, w & s = 0
		//		
		//		var ang_force = speed_contr * 1000 * time_step;
		//		
		//		pXcon_setmotor (car, vector(-ang_force, max_speed, 0), nullvector);
		//		pXcon_setmotor (car,vector(-ang_force, max_speed, 0), nullvector);
		
		   pXent_addvelcentral(car,vector(0,0,-10));
//			pXent_addvelcentral(FLwheel,vector(0,0,-50));
//			pXent_addvelcentral(FRwheel,vector(0,0,-50));
//			pXent_addvelcentral(BLwheel,vector(0,0,-50));
//			pXent_addvelcentral(BRwheel,vector(0,0,-50));

		camera.x = car.x - 250 *cos(car.pan);
		camera.y = car.y - 250 *sin(car.pan);
		camera.z = car.z + 50;
		camera.pan = car.pan;
		
		
		wait(1);
	}
}

void main()
{
	fps_max=60;
	
	video_mode=12;
	//ph_fps_max_lock=120;
	physX_open();
	level_load ("testlevel.wmb");
	simple_car();
	wait(5);
} 




It is buggy but it still does a little bit of what a car should do grin
Posted By: jweb

Re: converted physX car - 05/28/11 21:22

eheh Super THX you Progger
© 2024 lite-C Forums