Posted: 15th Apr 2003 13:46
I´m making carsimulator based to real physics.
I´v only done little of it, but there are some good formulas if you are interested. (specs are from corvette c5)
+ Code Snippet
set display mode 800,600,16
sync on
dim rpm(80)
dim gear#(6)
time#=timer()

numgears=6
gear#(1)=2.66
gear#(2)=1.78
gear#(3)=1.30
gear#(4)=1.0
gear#(5)=0.74
gear#(6)=0.5
gear#(7)=0
rpm(10)=400
rpm(15)=420
rpm(20)=435
rpm(25)=450
rpm(30)=460
rpm(35)=470
rpm(40)=480
rpm(45)=480
rpm(50)=460
rpm(55)=440
rpm(60)=400
rpm(65)=0
rpm(70)=0
rpm(75)=0
rpm(80)=0
rpm(85)=0
rpmredline=6000
cof#=0.3
faoc#=1.5
airdensity#=1.29
wheelbase#=2.5
cgheight#=1
cgrpros#=51.5
tfc#=1
mass#=1500
differentialratio#=3.42
transmissionef#=0.7
wheelradius#=0.34

gear=1
cgf#=(wheelbase#/100)*cgrpros#
cgr#=wheelbase#-cgf#
weight#=mass#*9.81
do
gosub controls
gosub engineforcecalculation
gosub slipcalculation
gosub longcalculation
gosub velocitycalculation
gosub weightshift
gosub drift
gosub errors
gosub graphics
sync : cls
loop

controls:
if upkey()=1 and pedal#<100 then inc pedal#,5
if downkey()=1 and pedal#>0 then dec pedal#,5
fbreaking#=0
if controlkey()=1 and velocity#>0 then fbreaking#=4000 : pedal#=0
return

engineforcecalculation:
gosub getmaxtorque
torque#=(maxtorque#/100)*pedal#
drivetorque#=torque#*gear#(gear)*differentialratio#*transmissionef#/wheelradius#
return

slipcalculation:
if velocity#<>0
slipratio#=(wheelrotation#*wheelradius#-velocity#)/velocity#
endif
return

longcalculation:
ftraction#=drivetorque#
cdrag#=0.5*cof#*faoc#*airdensity#
crr#=cdrag#*30
fdrag#=-1*cdrag#*velocity#^2
frr#=-1*crr#*velocity#
flong#=ftraction#+fdrag#+frr#
fslip#=(flong#/100)*abs(slipratio#)
fbreaking#=fbreaking#-fslip#
if fslip#>500 then fslip#=500
flong#=flong#+fslip#-fbreaking#
return

velocitycalculation:
acceleration#=flong#/mass#
dt#=(timer()-time#)/1000 : time#=timer()
velocity#=velocity#+dt#*acceleration#
position#=position#+dt#*velocity# 
return

weightshift:
wf#=(cgr#/wheelbase#)*weight#-(cgheight#/wheelbase#)*mass#*acceleration#
wr#=(cgf#/wheelbase#)*weight#+(cgheight#/wheelbase#)*mass#*acceleration#
return

drift:
driftforce#=tfc#*wr#
return

errors:
if velocity#<0 then velocity#=0 : drivetorque#=0 : flong#=0
return

graphics:
print "Pedal: ";pedal#;"%"
print "Gear: ";gear
print "Gearratio: ";gear#(gear)
print "Rpm: ";rpm#
print "Torque: ";torque#;"/";maxtorque#;"nM"
print "Ftraction: ";ftraction#;"N"
print "Fdrag: ";fdrag#;"N"
print "Frr: ";frr#;"N"
print
print "Flong: ";flong#;"N"
print "Fslip: ";fslip#;"N"
print "Dforce: ";driftforce#;"N"
print "Velocity: ";velocity#;"M/s"
print "               ";velocity#*3.6;"Km/h"
print "Travelled: ";position#;"M"
print
print "Weight: ";weight#;"N"
print "Wf: ";wf#;"N"
print "Wr: ";wr#;"N"

line 400,300+wr#/700,500,300+wf#/700

boxposition#=boxposition#+dt#*velocity#
if boxposition#>600 then boxposition#=0 
box 650,boxposition#,653,boxposition#+5
return

getmaxtorque:
wheelrotation#=velocity#/wheelradius#
crankshaftrotation#=gear#(gear)*differentialratio#*wheelrotation#
rpm#=(crankshaftrotation#*60)/(2*3.142)
if rpm#>rpmredline then rpm#=rpmredline
if rpm#<1000 then rpm#=1000
if rpm#>4800 and gear<numgears then inc gear
if rpm#<3000 and gear>1 then dec gear
r=10
if rpm#>1500 then r=15
if rpm#>2000 then r=20
if rpm#>2500 then r=25
if rpm#>3000 then r=30
if rpm#>3500 then r=35
if rpm#>4000 then r=40
if rpm#>4500 then r=45
if rpm#>5000 then r=50
if rpm#>5500 then r=55
if rpm#>6000 then r=60
if rpm#>6500 then r=65
if rpm#>7000 then r=70
if rpm#>7500 then r=75
if rpm#>8000 then r=80
rpmmiinus#=rpm#-r*100
torquemiinus=rpm(r+5)-rpm(r)
maxtorque#=((rpmmiinus#/500)*torquemiinus)+rpm(r)
return
Posted: 15th Apr 2003 14:06
And can someone tell me topspeed, because i programmed part of code here in school, so i cant test it. (i just need topspeed).
ou and any comments?
Posted: 15th Apr 2003 16:22
Hi,

I have no idea about car physics, but I like the concept.

Why don't you take it one step further and load the car parameters from a file. Then you could build different cars from different files and load them into the application. Suddenly, it becomes a whole lot more useful and configurable!
Posted: 15th Apr 2003 19:11
I got 240km/h but doesn't stay at top speed, goes up and down and shifts to 5
Posted: 16th Apr 2003 6:51
Wow, very nice, good job
Posted: 16th Apr 2003 7:37
TRS80Model1, normally a car wouldnt just get stuck at 240--less there was a governer or something-- because you wouldnt use the statement: IF spd > 240 THEN spd = 240, as normally there would be many conditions stopping a car from going over a certain speed.. friction, engine rpms, and transmission settings...

im gonna look at the code..can never get enough car sims lol...
Posted: 16th Apr 2003 12:01
Yes, i´m going to make file of car specs and such, but first i must finnish physics, there is allways something i havent noticed.
My slip calculations and breaking was wrong, i allso chance little of allmost everything. Now i get topspeed of 272Km/h. x-d
272Km/h is close to real, but it´s not perfect yet,example i must make inertia of wheels and axels.

I make another kind of graphics that show torque/hp curve at given rpm and rpm/speed/acceleration curves at given time.
Jerico2day, car can and normally stuck to topspeed if there´s no slopes on the road and if we wont turn wheel.
Reason why speed goes up and down is that when gear is 5 then car accelerates slowly and then gear chances to 6, what comes to gear 6 is that the gear ratio is so small that engine can´t produce enought power to keep car accelerating, speed and rpm starts to come down and some point gear chances back to 5 and car accelerates.
I don´t know if this is foult of my code or is it just the car that sucks.
Posted: 16th Apr 2003 14:23
is this for pro or classic cause i have classic and it doesnt seem to be working
Posted: 17th Apr 2003 12:26
I made it for classic, and i know there was errors like "no such array dimension" and maybe others, because i wasn´t able to test it in school, but you can fix thoes errors.
I advice you to not take that code serius, because i noticed that it sucks. I making new better code, lot better.
This is my plan(i dont show formulas yet):
rpm=angvelocity/gear ratio/differential ratio
enginemaxtorque<--torque at given rpm from curve
enginetorque<--enginemaxtorque/gaspedal%
driveforce<--drivetorque/wheelradius=enginetorque/gear ratio/differential ratio/transmissionefficiency
tractionforce<--driveforce/fdrag/frr
tractiontorque<--tractionforce
totaltorque<--tractiontorque/drivetorque/breaktorque
totalinertia<--wheelinertia/cshaftinertia
angacceleration<--totaltorque/totalinertia
angvelocity<--angacceleration
slipratio<--velocity/angvelocity
tractionforce<--tractionforce/tractionconstant/slipratio
acceleration<--tractionforce/mass
velocity<--acceleration
position<--velocity

I´m not sure if you understand this, but anyway.
Posted: 17th Apr 2003 16:48
Hey
Looking forward to this,I'm new to programming and i'm so sick of "rpg" "shooter" code.

ps. Talar ni Svenska?
Posted: 18th Apr 2003 2:59
zigma..its ... more physic than programming..
Posted: 18th Apr 2003 9:04

Chiwawa say:
zigma..its ... more physic than programming..


:-s So
An object moving like an car on a screen, yea it's alot of physics.
There is many sources out there fore good physic simulaitng, but mostly for C/C++. So i realy looking forward to see Bluedeep's work
Posted: 18th Apr 2003 23:53
yeah im agree with you...but in fact to understand his code..you should firstly understand car's physic...then you should maybe searsh ...some documentation on car's physic...before programming ..it it was just a...comment
Posted: 19th Apr 2003 5:43
I ran this in Pro got same results.. swinging from 225 - 241...
Nice job...
Posted: 22nd Apr 2003 10:08
I have little problem whith my slipforce calculations.
I used Paceijka´s formulas to make slip, this is imbortant because slipforce is force that moves car forward, and i can´t get it work.
Here is the page where i found those formulas:
http://www.racer.nl/reference/pacejka.htm
Propaply i have to find other way to make slip.
Posted: 22nd Apr 2003 10:15
Or... i think i make this work, if not good then bad.
that is so good formula that i can´t just dump that.
Posted: 27th Apr 2003 14:43
hi,
Im making a car simulator with dbpro based on physics too
I started 4 months ago but should be interested
to exchange with other people who work in the same way

Cheers
eric.felgines@cooperativesystem.com
Posted: 27th Apr 2003 17:53
If you are interested in programming car physics I recommend you take a look at the following link, scroll down to the section on car physics.

[href]http://www.gamedev.net/reference/list.asp?categoryid=28

Regards,
OzBot.
Posted: 29th Apr 2003 18:45
thanks OzBot

does anybody know which force feedback
driving wheel + gear + brake + accelerator
works well with dbpro ?

thanks a lot...

(I currently use logitech momo but force feedback does not work...)
Posted: 14th May 2003 4:36
Hi, i hope BlueDeep doesn't mind, but i'm currently expanding on his code, and only a couple of lines have been added, and many deleted, but it shows his code in 3d, currently going to add more code to allow for turning, and rewriting his code for other purpose's such as increased weight for more passengers in the car, weight transfer on turning etc, but have a look.

Edit - i have also changed the specs to those of a Dodge Viper