(Patch) Automatic gear shift
David Savinkoff <[email protected]>
| Newsgroups | gmane.games.torcs.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Bernhard, This patch improves human automatic gear shifting, making controlled drifting in TORCS much better. TORCS currently shifts gears by using car->_speed_x (a single component of a 3D vector). This is correct only when the car is traveling in the direction that is pointed, not when drifting or flying off-angle. Loss of control can no longer be attributed to improper automatic down-shifting while drifting. BTW using x, y and z vector components work better than just x and y (I drove various tracks for the past day to test TORCS). Note that this patch is more-or-less a hack-ish proof of concept. TORCS has been my high velocity entertainment for four years. Thanks, David ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk _______________________________________________ Torcs-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/torcs-users
human.cpp.diff
(text/x-patch, 1.4 KB)
--- src/drivers/human/human.cpp 2013-10-07 19:51:04.000000000 -0700
+++ src/drivers/human/human.cpp 2013-10-07 18:59:31.000000000 -0700
@@ -1043,6 +1043,8 @@
{
int gear, i;
int idx = index - 1;
+ double car_speed = sqrt(car->_speed_x*car->_speed_x + car->_speed_y*car->_speed_y + car->_speed_z*car->_speed_z);
+
tControlCmd *cmd = HCtx[idx]->CmdControl;
common_drive(index, car, s);
@@ -1110,10 +1112,10 @@
shiftThld = omega / car->_gearRatio[gear];
}
- if (car->_speed_x > shiftThld) {
+ if (car_speed > shiftThld) {
car->_gearCmd++;
} else if (car->_gearCmd > 1) {
- if (car->_speed_x < (omega / car->_gearRatio[gear-1] - 4.0)) {
+ if (car_speed < (omega / car->_gearRatio[gear-1] - 4.0)) {
car->_gearCmd--;
}
}
@@ -1126,13 +1128,13 @@
if (HCtx[idx]->AutoReverse) {
/* Automatic Reverse Gear Mode */
if (!HCtx[idx]->AutoReverseEngaged) {
- if ((car->_brakeCmd > car->_accelCmd) && (car->_speed_x < 1.0)) {
+ if ((car->_brakeCmd > car->_accelCmd) && (car_speed < 1.0)) {
HCtx[idx]->AutoReverseEngaged = 1;
car->_gearCmd = CMD_GEAR_R - CMD_GEAR_N;
}
} else {
/* currently in autoreverse mode */
- if ((car->_brakeCmd > car->_accelCmd) && (car->_speed_x > -1.0) && (car->_speed_x < 1.0)) {
+ if ((car->_brakeCmd > car->_accelCmd) && (car_speed > -1.0) && (car_speed < 1.0)) {
HCtx[idx]->AutoReverseEngaged = 0;
car->_gearCmd = CMD_GEAR_1 - CMD_GEAR_N;
} else {