Gear ratios with manual transmissions

Post your coding questions such as 'how to' here.
Post Reply
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Gear ratios with manual transmissions

Post by coolw » Thu Sep 06, 2007 4:34 am

Ok, probably the wrong forum, probably should be in a car forum :roll: , but I will give it a shot. :|

I am having a bit of trouble with how gears work in a car.
Lets say the engine is always running at 3,000 rpm.
In first gear the ratio is 2.315 : 1
In Second gear, the ratio is 1.568 :1
And so forth, untill you get to fifth gear.
Well as most of you guys who can read and understand english, I am making a car game.
So.. I could use someones help that knows alot or stuff about the transmission box.

In my signature is the latest release to my game, but here is the code I am working with right now.

Code: Select all

    If gear = 1 Then ratio = 2.315
    If gear = 2 Then ratio = 1.568
    If gear = 3 Then ratio = 1.195
    If gear = 4 Then ratio = 1.000
    If gear = 5 Then ratio = 0.915
    
    If rpm < rpmm Then
        rpm = 3 / ratio
    EndIf
    If rpm < 0 Then rpm = 0
where 3 = 3000 rpm
where rpm = rpm
where rpmm = rpm max - just like a real car :P

How would I get my car to work like a real car? :?
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)

User avatar
Sami The Great
Advanced Member
Posts: 485
Joined: Tue Aug 28, 2007 4:15 pm
Contact:

Re: Gear ratios with manual transmissions

Post by Sami The Great » Thu Sep 06, 2007 6:40 pm

I have made system time ago... Here is some usefull functions for you.

Code: Select all

This function gives move energy for Joule with mass and speed.
'm = mass (kg)
'v = speed ( m/s)
'gives Joule (J)
'use float numbers

Function GetEnergy(m#,v#)
v2# = v# ^ 2
Ek# = 0.5 * m# * v2#
Return Ek
EndFunction

Code: Select all

Function GetSpeed(m#,E#)
v# = Sqrt((2 * E / m))
Return v#
EndFunction
To move your car, rise energy, example: If Keyhit(28) then energy = energy + 10
Hope this helps. And sorry for my bad english.

User avatar
Valtzu
Active Member
Posts: 115
Joined: Sun Aug 26, 2007 2:40 pm
Location: Sauvo
Contact:

Re: Gear ratios with manual transmissions

Post by Valtzu » Thu Sep 06, 2007 7:29 pm

Hi,
I made a little example for you. Feel free to modify it.

Code: Select all

// Constants

Const PRIMARY_DRIVE  = 3.842
Const FINAL_DRIVE    = 2.5
Const GEARCOUNT      = 4
Const MAX_RPM        = 5000
Const WHEEL_DIAMETER = 65.0 

Dim GEAR_RATIO( GEARCOUNT ) As Float

// Gear ratios

GEAR_RATIO( 1 ) = 3.1712
GEAR_RATIO( 2 ) = 1.9433
GEAR_RATIO( 3 ) = 1.3826
GEAR_RATIO( 4 ) = 1.0828

currentGear = 1

Repeat
    // Changing gears
    If KeyHit(cbkeyup) And currentGear < GEARCOUNT Then
        currentGear + 1
        // Must calculate RPM for new gear
        rpm = (speed*100000.0) / ( 60.0*(WHEEL_DIAMETER*PI) / ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) * FINAL_DRIVE))
    EndIf
    If KeyHit(cbkeydown) And currentGear > 1 Then
        currentGear - 1
        // Must calculate RPM for new gear
        rpm = (speed*100000.0) / ( 60.0*(WHEEL_DIAMETER*PI) / ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) * FINAL_DRIVE))
    EndIf
    
    If KeyDown(cbkeyspace) Then
        // Let's calculate accelerate value, this is my own system
        acceleration# = ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) ^ 2 ) / 4
        
        rpm = Min(rpm + acceleration, MAX_RPM)
    Else
        rpm = Max(0, rpm - 5)
    EndIf
    
    // Current speed is calculated from rpm etc.
    speed = (WHEEL_DIAMETER*PI) / ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) * FINAL_DRIVE)*rpm*60.0/100000.0
    
    
    Text 0,0, "Current gear:     " + currentGear
    Text 0,15,"RPM:              " + rpm
    Text 0,30,"Calculated speed: " + speed
    DrawScreen
Forever
EDIT: ...and maybe this would help: http://en.wikipedia.org/wiki/Gear_ratio

coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Re: Gear ratios with manual transmissions

Post by coolw » Fri Sep 07, 2007 1:47 am

Valtzu wrote:Hi,
I made a little example for you. Feel free to modify it.

Code: Select all

// Constants

Const PRIMARY_DRIVE  = 3.842
Const FINAL_DRIVE    = 2.5
Const GEARCOUNT      = 4
Const MAX_RPM        = 5000
Const WHEEL_DIAMETER = 65.0 

Dim GEAR_RATIO( GEARCOUNT ) As Float

// Gear ratios

GEAR_RATIO( 1 ) = 3.1712
GEAR_RATIO( 2 ) = 1.9433
GEAR_RATIO( 3 ) = 1.3826
GEAR_RATIO( 4 ) = 1.0828

currentGear = 1

Repeat
    // Changing gears
    If KeyHit(cbkeyup) And currentGear < GEARCOUNT Then
        currentGear + 1
        // Must calculate RPM for new gear
        rpm = (speed*100000.0) / ( 60.0*(WHEEL_DIAMETER*PI) / ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) * FINAL_DRIVE))
    EndIf
    If KeyHit(cbkeydown) And currentGear > 1 Then
        currentGear - 1
        // Must calculate RPM for new gear
        rpm = (speed*100000.0) / ( 60.0*(WHEEL_DIAMETER*PI) / ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) * FINAL_DRIVE))
    EndIf
    
    If KeyDown(cbkeyspace) Then
        // Let's calculate accelerate value, this is my own system
        acceleration# = ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) ^ 2 ) / 4
        
        rpm = Min(rpm + acceleration, MAX_RPM)
    Else
        rpm = Max(0, rpm - 5)
    EndIf
    
    // Current speed is calculated from rpm etc.
    speed = (WHEEL_DIAMETER*PI) / ( ( PRIMARY_DRIVE * GEAR_RATIO( currentGear ) ) * FINAL_DRIVE)*rpm*60.0/100000.0
    
    
    Text 0,0, "Current gear:     " + currentGear
    Text 0,15,"RPM:              " + rpm
    Text 0,30,"Calculated speed: " + speed
    DrawScreen
Forever
EDIT: ...and maybe this would help: http://en.wikipedia.org/wiki/Gear_ratio

WOW! :P that is sweet, exactly what I am looking for! thanks! Gonna edit it now!
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)

Post Reply