Posted By: Toon
ODE physics car - 03/27/12 09:20
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.
Everything is working but the car acts weird
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!
ps. in void main() I have set the following properties for the physics-engine:
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 tongue](/ubb7/images/graemlins/default_dark/tongue1.gif)
Like I said before, I'm new to the whole Constraints-business...Any suggestions are welcome.
Thanks in advance!
![smile smile](/ubb7/images/graemlins/default_dark/smile.gif)
ps. in void main() I have set the following properties for the physics-engine:
Code:
ph_setgravity(vector(0,0,-386)); ph_selectgroup(8);