Hi there
Knowing the actual Miko x,y,z and the target of Miko (newx , newy, newz), we can position the camera and point to Miko x,y,z:
How can we get the newx, newy, newz ?
as easy as moving Miko lat say 10 units getting x,y,z and movig Miko back again...then we position the camera in newx,newy+??,newz and point camera to actual x,y,z. This methode show us just the back side of our prota...not so beautifull.
Here is the code applied to you snippet. You will need to get collision to position your prota on the floor.
Rem Project: My 3d Terrain
Rem Created: Wednesday, January 08, 2014
sync on
sync rate 60
rem set display mode 1920,1080,32
set window off
hide mouse
autocam off
make camera 1
backdrop off 1
set camera range 0.5, 30000,1
` movement
s# = 0.2
g_fTurn# = 0.2
` set the directory to media
` load our skybox
load object "skybox2.x", 200
set object light 200, 0
set object texture 200, 3, 0
position object 200, 1000, 2000, 4000
scale object 200, 30000, 30000, 30000
load object "normal.x",1
scale object 1,2000,2000,2000
position object 1,0,0,0
load object "MIKO_WALK.x", 2
load image "MIKO.TGA",1
texture object 2,1
xrotate object 2,-90
FIX OBJECT PIVOT 2
scale object 2,5,5,5
position object 2,500,-250,500
SET OBJECT SPEED 2,20000
loop object 2
` reset the directory
` main program loop
do
gosub userInput
gosub camerapos
gosub rotate_sky
gosub information
sync
loop
end
camerapos:
rem getting new coordinates of Miko
move object 2,-20
xx#=object position x(2)
yy#=object position y(2)
zz#=object position z(2)
rem reseting old position
move object 2,20
rem positioning camera in old coords. and pointing object
position camera 1,xx#,yy#+15,zz#
point camera 1,object position x(2),object position y(2)+10,object position z(2)
return
userInput:
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
` store new camera angle
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
` rotate camera
yrotate object 2, curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
rem xrotate camera 1,curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
if keystate(17)=1
MOVE OBJECT 2,1
endif
if keystate(31)=1
MOVE OBJECT 2,-1
endif
if keystate(30)=1
move object left 2,1
endif
if keystate(32)=1
move object left 2,-1
endif
if keystate(42)=1
inc player1y#
endif
if keystate(29)=1
dec player1y#
endif
return
rotate_sky:
yrotate object 200,sky#
inc sky#,0.01
return
information:
` show some information
` start printing at top of screen
set cursor 0, 0
` show frame rate
print "fps = " + str$ ( screen fps ( ) )
print ""
` current camera position
print ""
print "x = " + str$ ( camera position x ( ) )
print "y = " + str$ ( camera position y ( ) )
print "z = " + str$ ( camera position z ( ) )
print ""
` finally the polygon count
print "polygon count = " + str$ ( statistic ( 1 ) )
print ""
return
Another example using newvalue,newyvalue,newzvalue....
`Adjust the vehicle inclination with the terrain slope
create bitmap 1,50,50:for i= 1 to 1550:ink rgb(230,95,55),0:line rnd(60),i,i,rnd(130)
next i:blur bitmap 1,6:get image 1,10,10,50,50:delete bitmap 1
make matrix 1,10000.0,10000.0,25,25
prepare matrix texture 1,1,1,1
randomize matrix 1,350.0
update matrix 1
set ambient light 20
`The tank and the helper object (this helper will be hide)
make object sphere 1,0
make object sphere 5,0
make object box 2,50,5,80:color object 2,rgb(10,50,10)
make object box 3,40,20,50:offset limb 3,0,0,0,25
make mesh from object 1,3 :delete object 3
add limb 2,1,1 :add limb 2,2,1
scale limb 2,2,20,40,120 :offset limb 2,2,0,25,20:offset limb 2,1,0,10,-20
color limb 2,2,rgb(0,10,0):color limb 2,1,rgb(0,30,0)
x#=500
z#=500
sync on
do
if upkey()=1 then x#=newxvalue(x#,a#,1) : z#=newzvalue(z#,a#,1)
if downkey()=1 then x#=newxvalue(x#,a#,-1) : z#=newzvalue(z#,a#,-1)
if leftkey()=1 then a#=wrapvalue(a#-0.5)
if rightkey()=1 then a#=wrapvalue(a#+0.5)
`checking height of two helper
yb#=get ground height(1,object position x(1),object position z(1))
yb2#=get ground height(1,object position x(5),object position z(5))
`checking height of the tank
y#=get ground height(1,x#,z#)
`positioning helpers with the tank
position object 1,x#,yb#+40,z#
position object 2,x#,y#+30,z#
position object 5,x#,yb2#,z#
`turning
yrotate object 1,a#
yrotate object 2,a#
yrotate object 5,a#
`checking in front
move object 1,80
`checking on one side (left)
move object left 5,30
`pointing the tank to the coords of the helper 1
point object 2,object position x(1),object position y(1),object position z(1)
`rolling the tank its height less helper height
roll object left 2,y#-yb2#
`camera bihind the tank
cx#=newxvalue(x#,wrapvalue(a#+180),300)
cz#=newzvalue(z#,wrapvalue(a#+180),300)
cy#=get ground height(1,cx#,cz#)+100.0
position camera cx#,cy#+200,cz#
tr#=tr#+0.1
rotate limb 2,2,0,tr#,0
point camera x#,y#,z#
sync
loop
Cheers.
I'm not a grumpy grandpa