Hey, this is the code I'm using for the front wheels of my physics car.
// setup all 4 wheels
function InitWheel()
{
if (you.commonWheelHeight<=-100000) {
you.commonWheelHeight=my.z; // store z for other wheels to come
} else {
my.z=you.commonWheelHeight; // Set all wheels to same height
}
phent_settype(my, PH_RIGID, PH_SPHERE);
phent_setmass(my, you.massWheel, PH_SPHERE);
phent_setgroup(my, you.groupID);
phent_setfriction(my, you.fricWheel);
phent_setdamping(my, 15,you.dampWheel);
phent_setelasticity(my, 0, 100); // bounciness
you.wheelCounter+=1;
}
action FLInit()
{
var vecRight[3];
vec_set(vecRight,vector(0,-1,0)); // reset right vector (in case of level restart)
vec_rotate(vecRight, you.pan); // rotate right vector to correspond to car orientation
my.pan = 0;
my.passable = on;
while(!you) { wait(1);}
sleep(1);
InitWheel();
// make wheel constraint pointing up and towards center
you.wheelFL= phcon_add(PH_WHEEL, you, my);
phcon_setparams1(you.wheelFL, my.x, vector(0,0,1), vecRight);
phcon_setparams2(you.wheelFL, vector(0,0,0), nullvector, vector(you.suspensionERP, you.suspensionCFM,0));
my.passable = off;
}
The problem is when I start driving and turning my vehicle, sometimes the wheels start rotating weird and then turn back to the right position. Hope someone can see the problem in the code. Thanks anyway.