Hi,

I am working on this game, but it keeps freezing on me. The screen just freezes and I have to reboot. Does anyone have any idea how this can happen and what I should do different in this routine? Thanks in advance!!!!

--

targ=0

times=0

ugh=0

speed=1

xx=200+rnd(4800)

zz=200+rnd(4800)

hide mouse

sync on

draw to front

load image "grass1.bmp",1

landsize = 5000 : rem size of matrix - 5000 x 5000 .

rem Make a matrix landscape

make matrix 1,landsize,landsize,30,30 : rem size of each tile on matrix .

rem fog

set ambient light 50

rem fog on

rem fog distance 50

rem fog color 1

color backdrop 0

rem Prepare matrix with grass texture

prepare matrix texture 1,1,1,1

rem fill matrix with image 1 and set height to 0

fill matrix 1,0,1

rem randomize matrix 1, 100 : rem out this line if you want a flat matrix .

rem Load objects

load object "jeep.3ds",1 : rem jeep body .

load object "xwheel1.x",2 : rem front left wheel of jeep .

load object "xwheel1.x",3 : rem front right wheel of jeep .

load object "xwheel1.x",4 : rem rear right wheel of jeep .

load object "xwheel1.x",5 : rem rear left wheel of jeep .

` This is our compass

make object cone 7,5

rotate object 7,90,0,0

fix object pivot 7

rem ghost object on 7

` This is our first target

make object box 8,100,1000,100

position object 8,xx,0,zz

rem ghost object on 8

rem resize my wheels

scalevalue=50

scalevalue1=45

scale object 2,scalevalue1,scalevalue,scalevalue

scale object 3,scalevalue1,scalevalue,scalevalue

scale object 4,scalevalue1,scalevalue,scalevalue

scale object 5,scalevalue1,scalevalue,scalevalue

rem dummy object just to re orientate the jeep back to 0 ( yaw axis ) Turn object left and right axis.

make object plain 6,1,1

hide object 6

REM *** ALL VARIABLES ARE GLOBAL **********************************************************

rem physics variables

rem change these physics variables for various effects on the jeep .

rem drag and resistance together go to make a maximum velocity allowed . No maximum speed capping is needed .

DRAG# = .8 : rem wind resistance which slows the jeep down proprtionally to forward velocity .

RESISTANCE# = 5.0 : rem rolling resistance (slows the jeep down when free rolling)

CA_F# = -40 : rem cornering stiffness front = front slippyness of jeep .lower the number the less traction there is .

CA_R# = -40 : rem cornering stiffness rear = rear slippyness of jeep . lower the number the less traction there is .

CAR1_cartype_mass# = 350 : rem effects the sluggishness of the handling

CAR1_cartype_inertia# = 350 : rem how much momentum is generated by the jeep . Usual to set this equal to mass .

whichdrive = 1 : rem 0 = four wheel drive (best handling) : 1 = front wheel drive : 2 = rear wheel drive

rem leave these variables pretty much as they are .

delta_t# = 0.01

M_PI# = 3.1415926

tempcar = CA_R#

tempcaf = CA_F#

MAX_GRIP# = 2.0 : rem seems to have little efect

MULT# = 57 : rem =180 / M_PI#

MULT2# = .1 : rem MULT2# = fish tailing factor

CAR1_cartype = 1

CAR1_cartype_b# = 1.0

CAR1_cartype_c# = 1.0

CAR1_cartype_wheelbase# = CAR1_cartype_b# + CAR1_cartype_c#

CAR1_cartype_h# = 1.0

CAR1_cartype_width# = 1.5

CAR1_cartype_length# = 3.0

CAR1_cartype_wheellength# = 0.7

CAR1_cartype_wheelwidth# = 0.3

CAR1_car_position_wc_x# = landsize / 2 : rem start position x in world frame (centre of matrix)

CAR1_car_position_wc_y# = landsize / 2 : rem start position z in world frame (centre of matrix)

CAR1_car_velocity_wc_x# = 0

CAR1_car_velocity_wc_y# = 0

CAR1_car_angle# = 0

CAR1_car_angularvelocity# = 0

CAR1_car_steerangle# = 0

CAR1_car_throttle# = 0

CAR1_car_brake# = 0

front_slip = 0

rear_slip = 0

rem how much the jeep body rolls

rollscalefactor# = 49000 : rem 49000 .

minspeed = 5 : rem check if jeep is below the speed of 10, if so, then stop jeep. (counteracts drifting)

wheelpitchangle# = 0 : rem angle by which the wheels are rotated down, to simulate rolling forward as the jeep moves forward.

rem position jeep on the matrix at the start .

position object (1),CAR1_car_position_wc_x#,0,CAR1_car_position_wc_y#

gosub alignjeep

rem position camera in centre of the world frame just behind the jeep .

position camera landsize / 2,object position y(1)+10,(landsize / 2) - 40

camflag = 1 : rem camera tracking or stationary flag. 0 = stationary : 1 = follow jeep .

cameraspeed = 8 : rem speed of camera tracking .

REM **** MAIN LOOP ************************************************************************************************

while mouseclick()=0

set cursor 0,0

` The below is our scoring system

if object position z(1)>=zz-200

if object position z(1)=xx-200

if object position x(1) minspeed then pitch object down 2,wheelpitchangle#

endif

rem rotate front right wheel for steering and pitch for rolling along .

turn object right 3,CAR1_car_steerangle# * (180 / M_PI#)

if downkeypressed = 0

if velocity_x# > minspeed then pitch object down 3,wheelpitchangle#

endif

rem pitch rear wheels for rolling on ground .

if downkeypressed = 0

if velocity_x# > minspeed then pitch object down 4,wheelpitchangle#

endif

if downkeypressed = 0

if velocity_x# > minspeed then pitch object down 5,wheelpitchangle#

endif

return

rem CAR PHYSICS ALGORITHM BASED ON MARCO MONSTERS ORIGINAL C++ SOURCE CODE . ( cheers marco )

CARPHYSICS:

sn# = Sin(CAR1_car_angle# * MULT#)

cs# = Cos(CAR1_car_angle# * MULT#)

rem velocity_x# = forward speed of jeep .

velocity_x# = (cs# * CAR1_car_velocity_wc_y#) + (sn# * CAR1_car_velocity_wc_x#)

rem velocity_y# = sideways(lateral) speed of jeep .

velocity_y# = ((0-sn#) * CAR1_car_velocity_wc_y#) + (cs# * CAR1_car_velocity_wc_x#)

rem stop the car shuddering at different speeds - different grip levels at different speeds .

CA_R# = tempcar

CA_F# = tempcaf

CAR1_cartype_b# = 1.0

CAR1_cartype_c# = 1.0

if velocity_x# = 0

sgn# = 1

else

sgn# = 0 - 1

endif

ftraction_x# = 100.0 * (CAR1_car_throttle# - CAR1_car_brake# * Sgn#)

ftraction_y# = 0.0

resistance_x# = (0-( RESISTANCE# * velocity_x# + DRAG# * velocity_x# * Abs( velocity_x# ) ))

resistance_y# = (0-( RESISTANCE# * velocity_y# + DRAG# * velocity_y# * Abs( velocity_y# ) ))

force_x# = ftraction_x# + (Sin( CAR1_car_steerangle# * MULT# )) * flatf_x# + flatr_x# + resistance_x#

force_y# = ftraction_y# + (Cos( CAR1_car_steerangle# * MULT# )) * flatf_y# + flatr_y# + resistance_y#

torque# = CAR1_cartype_b# * flatf_y# - CAR1_cartype_c# * flatr_y#

acceleration_x# = force_x# / CAR1_cartype_mass#

acceleration_y# = force_y# / CAR1_cartype_mass#

angular_acceleration# = torque# / CAR1_cartype_inertia#

acceleration_wc_x# = (cs# * acceleration_y#) + (sn# * acceleration_x#)

acceleration_wc_y# = ((0-sn#) * acceleration_y#) + (cs# * acceleration_x#)

CAR1_car_velocity_wc_x# = CAR1_car_velocity_wc_x# + (delta_t# * acceleration_wc_x#)

CAR1_car_velocity_wc_y# = CAR1_car_velocity_wc_y# + (delta_t# * acceleration_wc_y#)

CAR1_car_angularvelocity# = CAR1_car_angularvelocity# + (delta_t# * angular_acceleration#)

CAR1_car_position_wc_x# = CAR1_car_position_wc_x# + (delta_t# * CAR1_car_velocity_wc_x#)

CAR1_car_position_wc_y# = CAR1_car_position_wc_y# + (delta_t# * CAR1_car_velocity_wc_y#)

rem position jeep at new world coordinates .

position object (1),CAR1_car_position_wc_x#,object position y(1),CAR1_car_position_wc_y#

if velocity_x# > minspeed : rem stop car below minimum speed to stop car shuddering due to inconsistancies in the physics engine .

CAR1_car_angle# = CAR1_car_angle# + (delta_t# * CAR1_car_angularvelocity#)

if CAR1_car_angle# > (M_PI# * 2) then CAR1_car_angle# = CAR1_car_angle# - (M_PI# * 2)

if CAR1_car_angle# 0 - .7 then CAR1_car_steerangle# = CAR1_car_steerangle# + ((0-M_PI#) / 180) * 7

If rightkeypressed = 1 and CAR1_car_steerangle# 0 - .1 then CAR1_car_steerangle# = 0

if CAR1_car_steerangle# > 0 then CAR1_car_steerangle# = CAR1_car_steerangle# - (M_PI# / 180) * 7

if CAR1_car_steerangle# h# then h#=trackh#

pitch object down 1, wrapvalue((length#/4.0) * (180 / M_PI#))

roll object left 1, wrapvalue((across#/4.0) * (180 / M_PI#))

rem raise jeep above ground

jeepheight# = 4.2

pitch object up 1,90

move object 1,jeepheight#

pitch object down 1,90

gosub positionwheels : rem place the wheels under the jeep

return

rem this routine effectively resets the physics engine by clearing all the physics variables .

rem only used if the jeep falls below minspeed where an engine reset is needed .

rem in my later versions of this algorithm, this is unesecary, but is left here as a debugging aid .

stopall:

CAR1_car_throttle# = 0

CAR1_car_brake# = 0

sgn# = 1

resistance_x# = 0

resistance_y# = 0

force_x# = 0

force_y# = 0

torque# = 0

acceleration_x# = 0

acceleration_y# = 0

velocity_x# = 0

velocity_y# = 0

angular_acceleration# = 0

acceleration_wc_x# = 0

acceleration_wc_y# = 0

CAR1_car_velocity_wc_x# = 0

CAR1_car_velocity_wc_y# = 0

CAR1_car_angularvelocity# = 0

flatf_x# = 0

flatr_x# = 0

flatr_y# = 0

flatf_y# = 0

yawspeed# = 0

rot_angle# = 0

sideslip# = 0

slipanglefront# = 0

slipanglerear# = 0

return

rem prints all physics variables . Useful for debuging but not actually used .

printall:

print "velocity_x# = ",velocity_x#

print "velocity_y# = ",velocity_y#

print "yawspeed# = ",yawspeed#

print "rot_angle# = ",rot_angle#

print "sideslip# = ",sideslip#

print "slipanglefront# = ",slipanglefront#

print "slipanglerear# = ",slipanglerear#

print "flatf_x# = ",flatf_x#

print "flatr_x# = ",flatr_x#

print "flatr_y# = ",flatr_y#

print "flatf_y# = ",flatf_y#

print "sgn# = ",sgn#

print "ftraction_x# =",ftraction_x#

print "ftraction_y# = ",ftraction_y#

print "rear_slip =",rear_slip

print "resistance_x# = ",resistance_x#

print "resistance_y# = ",resistance_y#

print "force_x# = ",force_x#

print "force_y# = ",force_y#

print "torque# = ",torque#

print "acceleration_x# = ",acceleration_x#

print "acceleration_y# = ",acceleration_y#

print "angular_acceleration# = ",angular_acceleration#

print "acceleration_wc_x# = ",acceleration_wc_x#

print "acceleration_wc_y# = ",acceleration_wc_y#

print "CAR1_car_velocity_wc_x# = ",CAR1_car_velocity_wc_x#

print "CAR1_car_velocity_wc_y# = ",CAR1_car_velocity_wc_y#

print "CAR1_car_position_wc_x# = ",CAR1_car_position_wc_x#

print "CAR1_car_position_wc_y# = ",CAR1_car_position_wc_y#

print "CAR1_car_angularvelocity# = ",CAR1_car_angularvelocity#

print "CAR1_car_angle# = ",CAR1_car_angle#

print "CAR1_car_throttle# = ",CAR1_car_throttle#

print "CAR1_car_brake# = ",CAR1_car_brake#

return

rem camera tracking routine

updatecamera:

if camflag = 1

cdestx#=object position x(1)

cdesty#=object position y(1)+5 : rem +5 units above the jeep. Track slightly above the jeep .

cdestz#=object position z(1)

ccurrentx#=camera position x()

ccurrenty#=camera position y()

ccurrentz#=camera position z()

ccurrentx#=curvevalue(cdestx#,ccurrentx#,cameraspeed)

ccurrenty#=curvevalue(cdesty#,ccurrenty#,cameraspeed)

ccurrentz#=curvevalue(cdestz#,ccurrentz#,cameraspeed)

position camera ccurrentx#,ccurrenty#,ccurrentz#

endif

point camera object position x(1),object position y(1),object position z(1)

return

--