pXcon_setwheel (ENTITY* entity, var SteerAngle, var MotorTorque, var BrakeTorque): void*
Applies a steer angle and an acceleration and braking torque to a wheel joint (PH_WHEEL), and wakes up the chassis entity the wheel is attached to. Use this function for moving and steering vehicles.
||Rotation angle about axis 1.
||Torque for acceleration about axis 2.
||Torque for braking about axis 2.
Wheels are no real physics constraints, but use a raycast vehicle algorithm. In this algorithm, rays are cast downwards from the wheel positions of the chassis, and determine the individual wheel behavior depending on the properties of the ground. This algorithm gives a more realistic behavior than a car build from physics constraints, but also causes some difficulties:
- PhysX does not return the position and angles of the wheel, thus leaving its calculation from the car orientation, suspension parameters, contact points, and axle speed as an excercise to the reader. Unfortunately, the axle speed returned by PhysX is wrong - it does not take wheel slip into account. It is not possible to calculate the 'real' axle speed from the wheel parameters, thus some approximations and educated guesses must be used.
- PhysX's wheel friction calculation uses a theoretically correct approach of a lateral and longitudinal friction curve with extremum and asymptote, but this curve apparently gets the torque and not the slip as input parameter, causing unrealistic acceleration and friction. For this reason, the friction curve must be scaled in real time from the wheel's speed and acceleration, and the wheel torque must be reduced at higher speeds.
- All these workarounds are applied in the ackphysX.dll library and in the car.c script, and are successful to a certain degree. For a really realistic car simulation, wheel physics have to be calculated on the CPU.
ENTITY* car = ent_create("car.mdl",vector(100,-200,40),NULL);
ENTITY* FLwheel = ent_create("wheel.mdl",vector(168,-170,17),NULL);
ENTITY* FRwheel = ent_create("wheel.mdl",vector(168,-230,17),NULL);
ENTITY* BLwheel = ent_create("wheel.mdl",vector(39,-170,17),NULL);
ENTITY* BRwheel = ent_create("wheel.mdl",vector(39,-230,17),NULL);
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
pXcon_setwheel (FRwheel,-5,0,0); // steer to the right
Constraints, pXcon_add, pXcon_setparams1, pXcon_setparams2,