Most Realistic Manual + Automatic Manual Transmission
Feb 22, 2015 7:16:25 GMT
Thunder, Famer, and 1 more like this
Post by F1Andre on Feb 22, 2015 7:16:25 GMT
Hi, there have never been an complete or realistic "Manual Transmission" script out there on the web or forum so here are some code for manual transmission.
Note that I have put list of objects at start just so that you know what each object is. The code is still missing a tachometer(RPM meter) but it will be up soon. There are some better ways to write code but this works for me so here it is.
used in my F1 game(called Final Formulae Racing). The project would actually be as big and complete as the F1 2010 game released by the Codemasters(the company that released and made the F1 game). You can also use it with your AI car(just use a seperate script or make a function of this script and call it when you need it with your AI car).
Enjoy the code.
-- Andre
Note that I have put list of objects at start just so that you know what each object is. The code is still missing a tachometer(RPM meter) but it will be up soon. There are some better ways to write code but this works for me so here it is.
/*
// this is the objects and what each one is(please don't include this in your code it just helps you)
IN_22 = Speed of the car in meters per second(even if your value print displays mp/h or km/h it should still be in meter per second
int steering = OUT_0; // (-1,1)
int throttle = OUT_1; // (-1,1
int brake = OUT_2; // (0,1)
int topSpeedFactor = OUT_3;
int acceleration = OUT_4;
int reverse = OUT_5; // (0,100)
int brakesPower = OUT_6;
int frontGrip = OUT_7;
int frontGripLat = OUT_8;
int rearGrip = OUT_9;
int rearGripLat = OUT_10;
int suspSpring = OUT_11;
int suspDamping = OUT_12;
int fwdMode = OUT_13; // (0 or 1)
int rwdMode = OUT_14; // (0 or 1)
*/
int gear = 0; // Actual gear that the user is currently on
int clutchDown = 0;
Quaternion SteerWheel;
Quaternion SteerDummy;
//***********F1 Car Output****************\\
int throttle; // you might want to remove this
void Main()
{
//**********************Set All Initialized "int" To A Certain Value Or Output******************\\
//*********F1 Car Output*********\\
OUT_1 = throttle; // might want to remove this
//*********************************Gear Change*************************************\\
// Change gear up
if(iKeyDown(iKeyCode("DIK_UP")) && clutchDown == 0)
{
gear += 1; // Increment the gear by 1
clutchDown = 1; // Helps keep a steady flow for when changing gear, without this gears will increment by more than one
}
// Change gear down
if(iKeyDown(iKeyCode("DIK_DOWN")) && clutchDown == 0)
{
gear -= 1; // Decrement the gear by one
clutchDown = 1; // Helps keep a steady flow for when changing gear, without this gears will increment by more than one
}
// Helps keep a steady flow for when changing gear, without this gears will increment by more than one
if(!iKeyDown(iKeyCode("DIK_UP")) && !iKeyDown(iKeyCode("DIK_DOWN")))
{
clutchDown = 0;
}
// Limit gear to a maximum of 7
if(gear > 7)
{
gear = 7;
}
// Limit gear to minimum of -1/reverse
if(gear < -1)
{
gear = -1;
}
//*************Set Gear Max and Min speed************//
if(gear == -1 && iKeyDown(iKeyCode("DIK_SPACE")))
{
OUT_1 = -1;
OUT_4 = 2;
OUT_3 = 3;
if(IN_22 > 8.3) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(30 km/h)
OUT_3 = 0;
}
if(gear == 0)
{
OUT_3 = 0;
OUT_4 = 0;
}
if(gear == 1)
{
OUT_4 = 1.7;
OUT_3 = 1.1;
if(IN_22 > 38.9) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(144 km/h)
OUT_3 = 0;
}
if(gear == 2)
{
OUT_3 = 1.2;
OUT_4 = 1.85;
if(IN_22 > 48.6) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(177 km/h)
OUT_3 = 0;
}
if(gear == 3)
{
OUT_3 = 1.4;
OUT_4 = 2.1;
if(IN_22 > 57.5) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear (207 km/h)
OUT_3 = 0;
}
if(gear == 4)
{
OUT_3 = 1.4;
OUT_4 = 2.2;
if(IN_22 > 66.4) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(239 km/h)
OUT_3 = 0;
}
if(gear == 5)
{
OUT_3 = 1.4;
OUT_4 = 2.23;
if(IN_22 > 78) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(273 km/h)
OUT_3 = 0;
}
if(gear == 6)
{
OUT_3 = 1.4;
OUT_4 = 2.3;
if(IN_22 > 86.4) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(311 km/h)
OUT_3 = 0;
}
if(gear == 7)
{
OUT_3 = 1.4;
OUT_4 = 2.4;
if(IN_22 > 95.2) // This limits the speed as soon it reaches a certain value so that the car can accelerate more efficiently and to limit speed at certain gear(332 km/h)
OUT_3 = 0;
}
OUT_44 = gear;
//*************Realistic Gear OUT_4******************\\
// If the gears are shifted early it creates a realistic acceleration by acelleration slow at first and increasing acceleration as it reaches its ideal shifting speed.( the vales that must be grater or less than should be the displayed value of your valueprint for car speed and the values must be in meter per second
//*********Gear 2********//
if(gear == 2 && IN_22 < 8.3){OUT_3 = 0.7; OUT_4 = 1;}
if(gear == 2 && IN_22 < 13.8 && IN_22 > 8.3){OUT_3 = 0.9;OUT_4 = 1.2;}
if(gear == 2 && IN_22 < 19.4 && IN_22 > 13.8) {OUT_3 = 1.1;OUT_4 = 1.3;}
if(gear == 2 && IN_22 < 25 && IN_22 > 19.4) {OUT_3 = 1.2; OUT_4 = 1.4;}
//********Gear 3*******//
if(gear == 3 && IN_22 < 8.3) {OUT_3 = 0.6; OUT_4 = 0.9; }
if(gear == 3 && IN_22 < 13.8 && IN_22 > 8.3) {OUT_3 = 0.8; OUT_4 = 1; }
if(gear == 3 && IN_22 < 19.4 && IN_22 > 13.8) {OUT_3 = 1; OUT_4 = 1.1; }
if(gear == 3 && IN_22 < 26 && IN_22 > 19.4) {OUT_3 = 1.1; OUT_4 = 1.2; }
if(gear == 3 && IN_22 < 33.5 && IN_22 > 26) {OUT_3 = 1.3; OUT_4 = 1.4; }
//********Gear 4*******//
if(gear == 4 && IN_22 < 8.3) {OUT_3 = 0.7; OUT_4 = 0.8; }
if(gear == 4 && IN_22 < 13.8 && IN_22 > 8.3) {OUT_3 = 0.8; OUT_4 = 1; }
if(gear == 4 && IN_22 < 19.4 && IN_22 > 13.8) {OUT_3 = 1; OUT_4 = 1.1; }
if(gear == 4 && IN_22 < 25 && IN_22 > 19.4) {OUT_3 = 1.1; OUT_4 = 1.2; }
if(gear == 4 && IN_22 < 30.5 && IN_22 > 25) {OUT_3 = 1.3; OUT_4 = 1.4; }
if(gear == 4 && IN_22 < 36 && IN_22 > 30.5) {OUT_3 = 1.4; OUT_4 = 1.4; }
if(gear == 4 && IN_22 < 41.6 && IN_22 > 36) {OUT_3 = 1.6; OUT_4 = 1.4; }
if(gear == 4 && IN_22 < 47.2 && IN_22 > 41.6) {OUT_3 = 1.6; OUT_4 = 1.5; }
//********Gear 5*******//
if(gear == 5 && IN_22 < 8.3) {OUT_3 = 0.7; OUT_4 = 0.7; }
if(gear == 5 && IN_22 < 13.8 && IN_22 > 8.3) {OUT_3 = 0.8; OUT_4 = 0.9; }
if(gear == 5 && IN_22 < 19.4 && IN_22 > 13.8) {OUT_3 = 1; OUT_4 = 1; }
if(gear == 5 && IN_22 < 25 && IN_22 > 19.4) {OUT_3 = 1.1; OUT_4 = 1.2; }
if(gear == 5 && IN_22 < 30.5 && IN_22 > 25) {OUT_3 = 1.3; OUT_4 = 1.4; }
if(gear == 5 && IN_22 < 36 && IN_22 > 30.5) {OUT_3 = 1.4; OUT_4 = 1.4; }
if(gear == 5 && IN_22 < 41.6 && IN_22 > 36) {OUT_3 = 1.6; OUT_4 = 1.4; }
if(gear == 5 && IN_22 < 47.2 && IN_22 > 41.6) {OUT_3 = 1.6; OUT_4 = 1.5; }
if(gear == 5 && IN_22 < 52.7 && IN_22 > 47.2) {OUT_3 = 1.6; OUT_4 = 1.6; }
if(gear == 5 && IN_22 < 58.3 && IN_22 > 52.7) {OUT_3 = 1.7; OUT_4 = 1.6; }
//********Gear 6*******//
if(gear == 6 && IN_22 < 8.3) {OUT_3 = 0.7; OUT_4 = 0.7; }
if(gear == 6 && IN_22 < 13.8 && IN_22 > 8.3) {OUT_3 = 0.8; OUT_4 = 0.9; }
if(gear == 6 && IN_22 < 19.4 && IN_22 > 13.8) {OUT_3 = 1; OUT_4 = 1; }
if(gear == 6 && IN_22 < 25 && IN_22 > 19.4) {OUT_3 = 1.1; OUT_4 = 1.2; }
if(gear == 6 && IN_22 < 30.5 && IN_22 > 25) {OUT_3 = 1.3; OUT_4 = 1.4; }
if(gear == 6 && IN_22 < 36 && IN_22 > 30.5) {OUT_3 = 1.4; OUT_4 = 1.4; }
if(gear == 6 && IN_22 < 41.6 && IN_22 > 36) {OUT_3 = 1.6; OUT_4 = 1.4; }
if(gear == 6 && IN_22 < 47.2 && IN_22 > 41.6) {OUT_3 = 1.6; OUT_4 = 1.5; }
if(gear == 6 && IN_22 < 52.7 && IN_22 > 47.2){OUT_3 = 1.6; OUT_4 = 1.6; }
if(gear == 6 && IN_22 < 58.3 && IN_22 > 52.7) {OUT_3 = 1.7; OUT_4 = 1.6; }
if(gear == 6 && IN_22 < 63.8 && IN_22 > 58.3) {OUT_3 = 1.7; OUT_4 = 1.7; }
if(gear == 6 && IN_22 < 69.4 && IN_22 > 63.8) {OUT_3 = 1.8; OUT_4 = 1.7; }
if(gear == 6 && IN_22 < 72&& IN_22 > 69.4) {OUT_3 = 1.8; OUT_4 = 1.8; }
//********Gear 7*******//
if(gear == 7 && IN_22 < 8.3) {OUT_3 = 0.7; OUT_4 = 0.6; }
if(gear == 7 && IN_22 < 13.8 && IN_22 > 8.3) {OUT_3 = 0.9; OUT_4 = 0.7; }
if(gear == 7 && IN_22 < 19.4 && IN_22 > 13.8) {OUT_3 = 1; OUT_4 = 0.9; }
if(gear == 7 && IN_22 < 25 && IN_22 > 19.4) {OUT_3 = 1.1; OUT_4 = 1.2; }
if(gear == 7 && IN_22 < 30.5 && IN_22 > 25) {OUT_3 = 1.2; OUT_4 = 1.3; }
if(gear == 7 && IN_22 < 36 && IN_22 > 30.5) {OUT_3 = 1.3; OUT_4 = 1.4; }
if(gear == 7 && IN_22 < 41.6 && IN_22 > 36) {OUT_3 = 1.5; OUT_4 = 1.4; }
if(gear == 7 && IN_22 < 47.2 && IN_22 > 41.6) {OUT_3 = 1.6; OUT_4 = 1.4; }
if(gear == 7 && IN_22 < 52.7 && IN_22 > 47.2) {OUT_3 = 1.6; OUT_4 = 1.6; }
if(gear == 7 && IN_22 < 58.3 && IN_22 > 52.7) {OUT_3 = 1.7; OUT_4 = 1.6; }
if(gear == 7 && IN_22 < 63.8 && IN_22 > 58.3) {OUT_3 = 1.7; OUT_4 = 1.7; }
if(gear == 7 && IN_22 < 69.4 && IN_22 > 63.8) {OUT_3 = 1.8; OUT_4 = 1.7; }
if(gear == 7 && IN_22 < 72 && IN_22 > 69.4) {OUT_3 = 1.8; OUT_4 = 1.8; }
if(gear == 7 && IN_22 < 75 && IN_22 > 72) {OUT_3 = 1.9; OUT_4 = 1.8; }
if(gear == 7 && IN_22 < 80.5 && IN_22 > 75) {OUT_3 = 1.9; OUT_4 = 1.9; }
//************Automatic Transmission(gear)***********//
// Gear will be changed if certain criteria is matched like the speed, when gear changes the above code will take over
// ***NOTE that this code should only be included if you want automatic transmission
if(IN_22 == 0)
gear = 0;
if(IN_22 > 0 && IN_22 < 33.3)
gear = 1;
if(IN_22 >= 33.3 && IN_22 < 38.8)
gear = 2;
if(IN_22 >= 38.3 && IN_22 < 51.4)
gear = 3;
if(IN_22 >= 51.4 && IN_22 < 61.1)
gear = 4;
if(IN_22 >= 61.1 && IN_22 < 75)
gear = 5;
if(IN_22 >= 75 && IN_22 < 83.3)
gear = 6;
if(IN_22 >= 83.3 && IN_22 < 100)
gear = 7;
//**************************Driving Controls****************************\\
// Controls for driving and shifting gears (steering is left and right arrow)
// Space = accelerate
// LControl = brake
// LArrow & RArrow = steering
// (Up&Down) || (A & D) || (A & Z) = gear shift
if(iKeyDown(iKeyCode("DIK_SPACE")))
{
throttle = 1;
}
else
throttle = 0;
if(iKeyDown(iKeyCode("DIK_LCONTROL")))
{
OUT_2 = 1;
OUT_6 = 2; // How fast/hard the car will brake
}
else
OUT_2 = 0;
// Gear shift is covered in "Gear Change"
// Steering will be handled thru the object settings
//*********************Steering, Traction, SteerWheel*****************//
//*********Steering**********//
// This decreases steering ability as the cars speed increases
if(IN_22 < 8.3) { OUT_7 = 1000; OUT_8 = 40; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 8.3 && IN_22 < 19.4) { OUT_7 = 1000; OUT_8 = 37; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 19.4 && IN_22 < 25) { OUT_7 = 1000; OUT_8 = 34; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 25 && IN_22 < 30.5) { OUT_7 = 1000; OUT_8 = 31; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 30.5 && IN_22 < 36.1) { OUT_7 = 1000; OUT_8 = 28; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 36.1 && IN_22 < 41.6) { OUT_7 = 1000; OUT_8 = 25; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 41.6 && IN_22 < 47.2) { OUT_7 = 1000; OUT_8 = 22; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 47.2 && IN_22 < 52.7) { OUT_7 = 1000; OUT_8 = 19; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 52.7 && IN_22 < 58.3) { OUT_7 = 1000; OUT_8 = 16; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 58.3 && IN_22 < 63.8) { OUT_7 = 1000; OUT_8 = 13; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 63.8 && IN_22 < 69.4) { OUT_7 = 1000; OUT_8 = 10; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 69.4 && IN_22 < 75) { OUT_7 = 1000; OUT_8 = 7; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 75 && IN_22 < 80.5) { OUT_7 = 1000; OUT_8 = 5; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 80.5 && IN_22 < 86.1) { OUT_7 = 1000; OUT_8 = 5; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 86.1 && IN_22 < 91.6) { OUT_7 = 1000; OUT_8 = 4; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 91.6 && IN_22 < 97.2) { OUT_7 = 1000; OUT_8 = 3; OUT_9 = 1000; OUT_10 = 100;}
if(IN_22 > 97.2 && IN_22 < 102.7) { OUT_7 = 1000; OUT_8 = 2; OUT_9 = 1000; OUT_10 = 100;}
}
This code is used on an extensivley modifeid car and with over 70 airfoils attached to it to create a realistic F1 car feel and acceleration. This code is also used for an F1 car and used in my F1 game(called Final Formulae Racing). The project would actually be as big and complete as the F1 2010 game released by the Codemasters(the company that released and made the F1 game). You can also use it with your AI car(just use a seperate script or make a function of this script and call it when you need it with your AI car).
Enjoy the code.
-- Andre