Quote: "(Wow, you played for an hour?!)"
Yep, set me up with any no-budget driving game with a half good game play mechanic and that's my evening sorted. I used to play 30 lap races on ToCa 2 on the PS1.
Quote: "Obviously a Lambo isn't a sensible dirt racing car, so I'd want something more suitable there too"
I really wouldn't worry about that. I never even occurred to me that the Lambo was out of place (as an aside, are we just calling it the "Lambo" because we don't know how to spell the full name and are too lazy to look it up?)
There is another reason for keeping the Lambo and for not putting in hills. If you had a dirt car / dune buggy and lots of humps and bumps then I would expect the car to bounce around. Which, if you're struggling with drifting mechanics, could be rather tricky to do. The flat track and sports car that sticks to the ground actually fits the game play.
And speaking of drifting, here's some code I knocked together:
remstart
car drifting demo
accelerate = up key
brake = down key
turn = left and right keys
remend
sync on
sync rate 60
autocam off
randomize timer()
`car
make object box 1, 10,3,20
`map
for i = 2 to 15
make object cube i, 100
position object i, (rnd(10)+5)*100,50,(rnd(10)+5)*100
color object i, rgb(100,rnd(100)*155,255)
next i
`terrain
make matrix 1, 2000,2000,10,10
`starting variables
car_xpos# = 100
car_ypos# = 1.5
car_zpos# = 100
car_facing = 0.0
car_speed_actual# = 0.0
car_xvel_target# = 0.0
car_zvel_target# = 0.0
car_xvel_actual# = 0.0
car_zvel_actual# = 0.0
`limits
car_speed_max# = 10.0
do
`turn the car
car_facing# = wrapvalue(car_facing# + rightkey() - leftkey())
`accelerate, braking and friction
if upkey() = 1
`accelerate
car_speed_actual# = curvevalue(car_speed_max#,car_speed_actual#,70)
else
if downkey() = 1
`apply brakes
car_speed_actual# = curvevalue(0.0,car_speed_actual#,20)
else
`apply friction
car_speed_actual# = curvevalue(0.0,car_speed_actual#,90)
endif
endif
`calculate the car's target x and z velocities based on the car's actual current speed
car_xvel_target# = car_speed_actual#*sin(car_facing#)
car_zvel_target# = car_speed_actual#*cos(car_facing#)
`curve the velocities from their current actual values to their target values
`the speed value (i.e. the third parameter) for the curve value function determines the amount of drift
`lower the value the less drift there is (a value of zero will give no drift)
car_xvel_actual# = curvevalue(car_xvel_target#,car_xvel_actual#,50)
car_zvel_actual# = curvevalue(car_zvel_target#,car_zvel_actual#,50)
`save old car position
car_xpos_old# = car_xpos#
car_zpos_old# = car_zpos#
`position car based on current actual velocities
car_xpos# = car_xpos# + car_xvel_actual#
car_zpos# = car_zpos# + car_zvel_actual#
position object 1, car_xpos#,car_ypos#,car_zpos#
rotate object 1,0,car_facing#,0
`detect collision with map
if object hit(1,0) > 0
car_xpos# = car_xpos_old#
car_zpos# = car_zpos_old#
car_xvel_actual# = car_xvel_actual#*-0.5
car_zvel_actual# = car_zvel_actual#*-0.5
car_speed_actual# = car_speed_actual#*-1
position object 1, car_xpos#,car_ypos#,car_zpos#
endif
`position camera
position camera car_xpos#,car_ypos+10,car_zpos#
rotate camera 0,car_facing#,0
move camera -40
pitch camera down 10
set cursor 0,0
print "actual xvel# : ", car_xvel_actual#
print "target xvel# : ", car_xvel_target#
print ""
print "actual zvel# : ", car_zvel_actual#
print "target zvel# : ", car_zvel_target#
sync
loop
This gives a very arcade like drifting effect and the only real bit of maths is a bit of trig.
The core of it is to split the direction the car is facing from the direction the car is moving. Then to have a transition between what the car is actually doing to what you want it to do. This is done using the CURVE VALUE command to transition from the actual velocity to the target velocity. Hopefully looking at the code it'll make sense.
What you could do is change the CURVE VALUE speed parameter based on say:
- how fast the car is going (if the car is travelling fast you could have more drifting).
- how fast the player move the joystick left or right (i.e. jerk left to initiate a drift).
- for key board controls increase the drift based on how long they are turning for.
Now you can drift, you must finish this game.