@zircher and cyberflame: don't worry guys, thanks anyway, as the problem is sorted now
@bibz1st: lol!
BTW for not making another post...someone can help me with that tilting problem? I tried to adapt it and screws up very bad, and don't know why
here's the code, if you wanna test it, download the media at the start of this thread then replace the source code with this:
landize=5000
x#=landsize
z#=landsize
gosub Init
gosub Variables
gosub LoadAll
gosub LoadScene
gosub LoadPlayer
for x= 4 to 7
make object cube x,5
next x
do
gosub Player
gosub Scenery
gosub Info
sync
loop
Player:
` gosub MovePlayer
gosub TiltPlayer
gosub TurretPlayer
gosub BulletsPlayer
return
MovePlayer:
if leftkey()=1 then lf=1 else lf=0
if rightkey()=1 then rt=1 else rt=0
if upkey()=1 then fw=1 else fw=0
if downkey()=1 then bw=1 else bw=0
if fw=1
spd#=spd#+1
endif
if bw=1
spd#=spd#-1
endif
if lf=1 and spd#<>0
pay#=wrapvalue(pay#-spd#)
endif
if rt=1 and spd#<>0
pay#=wrapvalue(pay#+spd#)
endif
if spd#>0 then spd#=spd#-0.040
if spd#<0 then spd#=spd#+0.040
if spd#>0.24 then spd#=0.24
if spd#<-0.24 then spd#=-0.24
move object Ppv,spd#
yrotate object Ppv,pay#
yrotate object Pta,pay#
return
TiltPlayer:
rem Control tank
if upkey()=1 and s#<0.4 then s#=s#+0.2
if downkey()=1 and s#>-0.4 then s#=s#-0.2
if leftkey()=1 then s#=s#+0.01 : a#=wrapvalue(a#-2)
if rightkey()=1 then s#=s#+0.01 : a#=wrapvalue(a#+2)
rem Calculate tank data
oldx#=x#
oldz#=z#
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
s#=s#/1.2
landsize=5000
shx#=shx#+(x#-oldx#)
shz#=shz#+(z#-oldz#)
mx#=(x#-landsize)-shx# : mz#=(z#-landsize)-shz#
rem Calculate four X+Z coordinates for each corner
foot#=50
ta#=wrapvalue(a#-35)
frontleftx#=newxvalue(x#,ta#,foot#) : frontleftz#=newzvalue(z#,ta#,foot#)
ta#=wrapvalue(a#+35)
frontrightx#=newxvalue(x#,ta#,foot#) : frontrightz#=newzvalue(z#,ta#,foot#)
ta#=wrapvalue(a#+215)
backleftx#=newxvalue(x#,ta#,foot#) : backleftz#=newzvalue(z#,ta#,foot#)
ta#=wrapvalue(a#+145)
backrightx#=newxvalue(x#,ta#,foot#) : backrightz#=newzvalue(z#,ta#,foot#)
rem Calculate degree of tilting from corner heights
frontlefth#=get ground height(1,frontleftx#-mx#,frontleftz#-mz#)
frontrighth#=get ground height(1,frontrightx#-mx#,frontrightz#-mz#)
backlefth#=get ground height(1,backleftx#-mx#,backleftz#-mz#)
backrighth#=get ground height(1,backrightx#-mx#,backrightz#-mz#)
across#=((frontrighth#-frontlefth#)+(backrighth#-backlefth#))/2.0
length#=((backlefth#-frontlefth#)+(backrighth#-frontrighth#))/2.0
rem just to show where frontleft,frontright etc are
position object 4,frontleftx#,frontlefth#,frontleftz#
position object 5,frontrightx#,frontrighth#,frontrightz#
position object 6,backleftx#,backlefth#,backleftz#
position object 7,backrightx#,backrighth#,backrightz#
rem Update tank model
h#=get ground height(1,x#-mx#,z#-mz#)
trackh#=(frontlefth#+frontrighth#+backlefth#+backrighth#)/4.0
if trackh#>h# then h#=trackh#
position object Ppv,x#,h#,z#
position object Pta,x#,h#,z#
yrotate object Ppv,a#
rotate object Pta,wrapvalue(length#/4.0),a#,wrapvalue(across#/4.0)
x#=object position x(Ppv)
z#=object position z(Ppv)
return
TurretPlayer:
Chase_Cam_Turret(Pta,16.0,10.0)
if inkey$()="t" then ptay#=curveangle(ptay#,wrapvalue(ptay#-2.5),10)
if inkey$()="y" then ptay#=curveangle(ptay#,wrapvalue(ptay#+2.5),10)
yrotate object Ptu,ptay#
ptay#=object angle y(Ptu)
pay#=object angle y(Pta)
return
BulletsPlayer:
if spacekey()=1 and object visible(bullet)=0
show object bullet
lx#=object position x(Pta)
ly#=limb position y(Ptu,lmb)
lz#=object position z(Pta)
lax#=limb direction x(Ptu,lmb)
lay#=limb direction y(Ptu,lmb)
laz#=limb direction z(Ptu,lmb)
rotate object bullet,lax#,lay#,laz#
position object bullet,lx#,ly#,lz#
move object bullet,-4
tt=0
endif
if object visible(bullet)=1
move object bullet,-2
tt=tt+1
set cursor 0,300
print tt
if tt>25:hide object bullet:tt=0:endif
endif
return
Scenery:
position object sky,px#,0,pz#
turn object right sky,0.1
xp#=cos(135)*60
zp#=sin(135)*60
position object Sun,px#+xp#,46,pz#+zp#
return
Info:
text 0,0,"FPS: " + str$(screen fps())
text 0,18,"Speed: " + str$(spd#)
text 0,18*2,"Polys: " + str$(statistic(1))
text 0,18*3,"TankRotX: " + str$(object angle x(Pta))
text 0,18*4,"TankRotY: " + str$(object angle y(Pta))
text 0,18*5,"TankRotZ: " + str$(object angle z(Pta))
text 0,18*6,"PlayerX: " + str$(object position x(Pta))
text 0,18*7,"PlayerY: " + str$(object position y(Pta))
text 0,18*8,"PlayerZ: " + str$(object position z(Pta))
text 0,18*9,"BulletX: " + str$(object position x(10))
text 0,18*10,"BulletY: " + str$(object position y(10))
text 0,18*11,"BulletZ: " + str$(object position z(10))
text 0,18*13,"SunX: " + str$(object position x(Sun))
text 0,18*14,"SunY: " + str$(object position y(Sun))
text 0,18*15,"SunZ: " + str$(object position z(Sun))
text 0,18*17,"vx2: " + str$(vx2)
text 0,18*18,"vy2: " + str$(vy2)
return
Init:
set emulation off
randomize timer()
for a=1 to 100
a=rnd(99999999)
next a
sync on
sync rate 40
set display mode 640,480,16
hide mouse
autocam off
return
Variables:
`Player Tank
`Player Turret
Pta=11
Ptu=22
`Player's pivot
Ppv=1
`Skysphere
Sky=100
`Sun dummy
Sun=105
`Bulletnumber (for testing)
bullet=10
LF1=150
LF2=151
LF3=152
LF4=153
LF5=154
Ptex1=1
Ptex2=2
Ptex3=3
GroundTex=10
Skytex=100
dim CamRot1#(0)
return
LoadAll:
load image "textures\warrior.bmp",Ptex1
load image "textures\warrior2.bmp",Ptex2
load image "textures\grass08.bmp",GroundTex,1
load image "textures\005ciel.jpg",skytex
`load image "d:\downloads\clouds2.jpg",skytex
return
LoadPlayer:
load object "models\tank.3ds",Pta
load object "models\turret.3ds",Ptu
glue object to limb Ptu,Pta,0
texture object Pta,Ptex1
texture object Ptu,Ptex1
scale object Pta,50,50,50
`scale object Ptu,10,10,10
yrotate object Pta,180
`yrotate object Ptu,180
fix object pivot Pta
`fix object pivot Ptu
position object Pta,500,0,500
make object cube Ppv,0.01
position object Ppv,500,get ground height(1,500,500),500
px#=object position x(Ppv)
py#=object position y(Ppv)
pz#=object position z(Ppv)
position camera px#,py#,pz#
make object sphere bullet,0.5
make object cube 30,1
make object cube 40,2
hide object bullet
make mesh from object 1,40
for a=0 to 999
if limb exist(Ptu,a)=0
exit
endif
next a
add limb Ptu,a,1
lmb=a
offset limb Ptu,lmb,0,9,-14
hide object 30
hide limb Ptu,lmb
return
LoadScene:
make matrix 1,5000,5000,64,64
set matrix texture 1,1,1
prepare matrix texture 1,GroundTex,1,1
randomize matrix 1,10
SmoothMatrix(1,32,32)
f=160
fogcolor=rgb(f,f,f)
fog on
fog color fogcolor
fog distance 600-100
set camera range 1,600
make object sphere Sky,600
scale object sky,-100,-50,-100
position object sky,500,0,500
texture object Sky,Skytex
zrotate object sky,180
fix object pivot sky
scale object texture sky,2,2
set object sky,1,1,1,1,0,1,0
make light 1
set directional light 1,-1,-1,-1
set ambient light 50
backdrop off
fade object Sky,50
return
function chase_cam_turret(id,camDist#,camHeight#)
`work out the angle of the object being chased
yAng#=curveangle(wrapvalue(object angle y(id) + object angle y(id+11)+180),yAng#,10)
`grab the objects current position
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
`other variables
`camDist=12
`camHeight=5
remstart
`work out new position
xCamPos#=curvevalue(newxvalue(xPos#,yAng#,camDist),xCamPos#,10)
zCamPos#=curvevalue(newzvalue(zPos#,yAng#,camDist),zCamPos#,10)
remend
xCamPos#=newxvalue(xPos#,yAng#,camDist#)
zCamPos#=newzvalue(zPos#,yAng#,camDist#)
xCamPos#=curvevalue(xCamPos#,camera position x(),8)
yCamPos#=curvevalue(yCamPos#,camera position y(),8)
zCamPos#=curvevalue(zCamPos#,camera position z(),8)
`work out camera height
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight#
if yCamPos# < yPos#+camHeight# then yCamPos#=yPos#+camHeight#
`update camera position
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camHeight#,zPos#
endfunction
`---------
`chase cam
`---------
function chase_cam_die(id,camDist#,camHeight#)
CamRot1#(0)=CamRot1#(0)+1
`work out the angle of the object being chased
yAng#=curveangle(wrapvalue(object angle y(id)+object angle y(id+11)+CamRot1#(0)),yAng#,10)
`grab the objects current position
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
`other variables
`camDist=15
`camHeight=10
`work out new position
xCamPos#=newxvalue(xPos#,yAng#,camDist)
zCamPos#=newzvalue(zPos#,yAng#,camDist)
xCamPos#=curvevalue(xCamPos#,object position x(id),8)
yCamPos#=curvevalue(yCamPos#,object position y(id),8)
zCamPos#=curvevalue(zCamPos#,object position z(id),8)
`work out camera height
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos# < yPos#+camHeight then yCamPos#=yPos#+camHeight
`update camera position
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camheight,zPos#
move camera 0-camDist
point camera xPos#,yPos#,zPos#
endfunction
function SmoothMatrix(n,tx,ty)
for z=1 to ty-1
for x=1 to tx-1
rem get matrix height
h8#=get matrix height(n,x,z-1)
h4#=get matrix height(n,x-1,z)
h#=get matrix height(n,x,z)
h2#=get matrix height(n,x,z)
rem X angle by using heights
x1#=(x-1)*25.0 : y1#=h#
x2#=(x+0)*25.0 : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem X angle by using heights
z1#=(z-1)*25.0 : y1#=h2#
z2#=(z+0)*25.0 : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem create normal
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem smooth the matrix
set matrix normal n,x,z,nx#,ny#,nz#
next x
next z
endfunction
Thanks in advance

-DARKGuy