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,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
ODE physics car #398066
03/27/12 09:20
03/27/12 09:20
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
Hi guys,

I'm trying to create a simple ODE-physics (a7) car, I never really looked into physics so far except for simple boxes and spheres / cylinders.

This is what I've got so far. When it's done I'd be happy to share the complete code with the community.

Code:
void wheel()
{	
	wait(1);
	
	//set loc_str to bone-names for wheels (frontleft, frontright, backleft, backright)
	STRING* loc_str = "#64";
	switch(my.Wheel)
	{
		case 1:str_cpy(loc_str,"fl");break;
		case 2:str_cpy(loc_str,"fr");break;
		case 3:str_cpy(loc_str,"bl");break;
		case 4:str_cpy(loc_str,"br");break;
	}
	
	VECTOR loc_vec;
	ANGLE  loc_ang;
	
	vec_for_bone(loc_vec.x,you,loc_str);
	ang_for_bone(loc_ang.pan,you,loc_str);
	
	vec_set(my.x,loc_vec);
	vec_set(my.pan,loc_ang);
	
	if(my.Wheel == 1 || my.Wheel == 3)//turn left wheels 180 degrees
	{
		my.pan += 180;
	}
	
	//sets hull, mass, friction and damping
	phent_reg(PH_SPHERE,20,100,75);
	phent_setgroup(me,2);
	
	var hingeID = phcon_add(PH_WHEEL,you,me);
	phcon_setparams1(hingeID,loc_vec.x,vector(0,0,1),vector(0,1,0));
	
	var pan_limit;
	if(my.Wheel == 1 || my.Wheel == 2)
	{
		pan_limit = 45;
	}
	else
	{
		pan_limit = 0;
	}
	
	phcon_setparams2(hingeID,vector(-pan_limit,pan_limit,0),nullvector,nullvector);
	phcon_setmotor(hingeID,vector(-45,45,0),nullvector,nullvector);
	
	wait(1);
	c_setminmax(me);
	
	var wheel_force=0;
	var wheel_tlt=0;
	while(1)
	{
		if(my.Wheel == 1 || my.Wheel == 2)//front-wheels
		{
			phent_addtorqueglobal(me,vector(0,0,wheel_force));
			wheel_force = (key_cul-key_cur) * 256 * time_step;
		}
		else
		{
			if(my.Wheel == 3)
			{
				wheel_force = -wheel_force;
			}
			phent_addtorquelocal(me,vector(0,wheel_force,0));
			
			wheel_force = (key_cuu-key_cud) * 1024 * time_step;
		}
		
		wait(1);
	}
}

void car()
{
	phent_reg(PH_BOX,200,75,75);
	phent_setgroup(me,2);
	
	wait(1);
	c_setminmax(me);
	
	you = ent_create(wheel01_mdl,nullvector,wheel);
	you.Wheel = 1;
	you = ent_create(wheel01_mdl,nullvector,wheel);
	you.Wheel = 2;
	you = ent_create(wheel01_mdl,nullvector,wheel);
	you.Wheel = 3;
	you = ent_create(wheel01_mdl,nullvector,wheel);
	you.Wheel = 4;
	
	VECTOR loc_vec;
	
	while(1)
	{
		camera.x = my.x - 256 * cos(my.pan);
    	camera.y = my.y - 256 * sin(my.pan);
    	camera.z = my.z + 256;
    	vec_set(loc_vec,my.x); 
  		vec_sub(loc_vec,camera.x);
  		vec_to_angle(camera.pan,loc_vec);
		wait(1);
	}
}



Everything is working but the car acts weird tongue The wheel's pan is turning to the left, I know it has something to do with the motor but I can't just take it out because the wheel should be centered automaticly...

Like I said before, I'm new to the whole Constraints-business...Any suggestions are welcome.

Thanks in advance! smile

ps. in void main() I have set the following properties for the physics-engine:

Code:
ph_setgravity(vector(0,0,-386));
ph_selectgroup(8);



Re: ODE physics car [Re: Toon] #398077
03/27/12 14:16
03/27/12 14:16
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline
Serious User
darkinferno  Offline
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
you say the car act fine ? if so, just hide the the actual physics wheels and use a restricted model for the visible wheels

Re: ODE physics car [Re: darkinferno] #398448
04/02/12 09:08
04/02/12 09:08
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
What I eventually want is a simple ODE-physics car, without workarounds wink

Can someone plz try the code and help me out...the wheels need to steer to the center when key_cul and key_cur are NOT pressed.

I uploaded the complete project (including magnificent car model wink ) here: http://www.toonlenkens.nl/projects/ODECar.zip.

Just unzip and run race.c

Last edited by Toon; 04/02/12 09:08.
Re: ODE physics car [Re: Toon] #401206
05/15/12 13:43
05/15/12 13:43
Joined: Nov 2003
Posts: 433
The Netherlands
T
Toon Offline OP
Senior Member
Toon  Offline OP
Senior Member
T

Joined: Nov 2003
Posts: 433
The Netherlands
Can someone plz help grin !


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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