Thanks for the help guys.
Thats right
if i dont move it there it isnt tested if not the upkey or downkey is pressed... in which case its quite useless
i found and fixed another bug as well! As the code is now, as you suggest, you can speed up and use the friction to glide of the matrix... not good.
rem sort out movement and check for falloff
testX#=newxvalue(playerX#, playerA#, speed#*3)
testZ#=newzvalue(playerZ#, playerA#, speed#*3)
if testX#<worldsize and testX#>0 and testZ#<worldsize and testZ#>0
if upkey()=1 then speed#=(speed#+acc#)*friction#
if downkey()=1 then speed#=(speed#-acc#)*friction#
if upkey()=0 and downkey()=0 then speed#=speed#*friction#
if speed#>maxspeed# then speed#=maxspeed#
rem move it with the calculated speed
move object 1,speed#
endif
Well... now on to the next problem
. Now when friction and acceleration is implented i thought it would be good the have a maximum speed allowed. But for some reason it wont go all the way up to the max speed. I dont know why, i only test for the mexspeed once and do not change the value.
*Again*
heres the entire source... *sigh* lol
Rem Project: hydralisk
Rem Created: 2004-05-30 00:47:47
Rem ***** Main Source File *****
rem setup
sync on
sync rate 60
rem un-rem to have window mode
rem set window on
rem set window position 150,75
autocam off
rem variables
worldsize=5000
turnspeed#=3.0
speed#=0.0
friction#=0.97
acc#=0.1
maxspeed#=4.0
rem make matrix
make matrix 1,worldsize,worldsize,50,50
load image "grass.bmp",1
prepare matrix texture 1,1,1,1
fill matrix 1,0,1
randomize matrix 1,100
update matrix 1
rem make fog
fog on
backdrop on
set camera range 1,2500
fog distance 1500
fog color RGB(192,192,192)
color backdrop RGB(0,128,255)
rem make temp player character
make object cube 1,10
position object 1,2500,100,2500
remstart ...problem: it wont load :(
load object "rhino.3ds",2
position object 2,2600,100,2600
size=30
scale object 2,size,size,size
glue object to limb 2,1,0
remend
playerX#=object position x(1)
playerZ#=object position z(1)
playerY#=get ground height(1,playerX#,playerZ#)
rem MAIN LOOP
DO
gosub move
gosub tilt
gosub print_status
rem refresh screen
sync
LOOP
move:
rem store player heading
playerA#=object angle Y(1)
rem sort out movement and check for falloff
testX#=newxvalue(playerX#, playerA#, speed#*3)
testZ#=newzvalue(playerZ#, playerA#, speed#*3)
if testX#<worldsize and testX#>0 and testZ#<worldsize and testZ#>0
if upkey()=1 then speed#=(speed#+acc#)*friction#
if downkey()=1 then speed#=(speed#-acc#)*friction#
if upkey()=0 and downkey()=0 then speed#=speed#*friction#
if speed#>maxspeed# then speed#=maxspeed#
rem move it with the calculated speed
move object 1,speed#
endif
rem turn it
if rightkey()=1 then playerA#=playerA#+turnspeed#
if leftkey()=1 then playerA#=playerA#-turnspeed#
rem get the new position
playerX#=object position x(1)
playerZ#=object position z(1)
playerY#=get ground height(1,playerX#,playerZ#)
rem and place it there, increase the Y coord so it isnt half burried
position object 1,playerX#,playerY#+5.0,playerZ#
rem place the camera according to the players position
camX#=newxvalue(playerX#,playerA#-180,100)
camZ#=newzvalue(playerZ#,playerA#-180,100)
camY#=get ground height(1,camX#,camZ#)
rem do the actual placement
position camera camX#,camY#+50,camZ#
point camera playerX#,playerY#+25,playerZ#
return
tilt:
rem how for around the vehicle to check
checkrange=1
rem check the height in a square around the vehicle
a#=playerA#
frontX#=newxvalue(playerX#,a#,checkrange)
frontZ#=newzvalue(playerZ#,a#,checkrange)
a#=playerA#+180
backX#=newxvalue(playerX#,a#,checkrange)
backZ#=newzvalue(playerZ#,a#,checkrange)
a#=playerA#+90
leftX#=newxvalue(playerX#,a#,checkrange)
leftZ#=newzvalue(playerZ#,a#,checkrange)
a#=playerA#-90
rightX#=newxvalue(playerX#,a#,checkrange)
rightZ#=newzvalue(playerZ#,a#,checkrange)
rem work out the tilt value based on the heights gotten above
frontheight#=get ground height(1,frontX#,frontZ#)
backheight#=get ground height(1,backX#,backZ#)
leftheight#=get ground height(1,leftX#,leftZ#)
rightheight#=get ground height(1,rightX#,rightZ#)
rem work out how much to tilt the vehicle
xA#=wrapvalue((backHeight#-frontHeight#)*20)
zA#=wrapvalue((leftHeight#-rightHeight#)*20)
rem smooth it a bit
xA#=curveangle((backHeight#-frontHeight#)*20,object angle x(1),5)
zA#=curveangle((leftHeight#-rightHeight#)*20,object angle z(1),5)
rem ...and tilt it!
rotate object 1,xA#,playerA#,zA#
return
print_status:
rem print statuses like the speed
set cursor 0,0
print "speed: " : print speed#
print "friction: " : print friction#
print "acceleration: " : print acc#
print "maxspeed: " : print maxspeed#
return
Added so that it prints the speed and stuff as well
[edit]
btw, is there any way to declear a max value of decimals printed in the print command? The 15th decimal in the speed value isnt that interesting
just clutters up...
thanks again
Dreaming of creating a highly advanced AI mind