Your comment is welcome and absolutely right in relation to the result.
if you like math, the same result can be had with:
x1#=x#+cos(angle#+90.0)*-distance
z1#=z#+sin(angle#+90.0)*distance
position object 11,x1#,h#+10,z1#
yrotate object 11,angle#
I think it's a matter of coding style.
I prefer more "verbose" coding based on more variables available for tweaking .
Notice that adding an offset to:
yrotate object 11,angle# you can rotate the object at will by manipulating the offset.
here's a refined version of the previous post code:
rem Player = object 10
set display mode 1920,1080,32
SYNC ON
SYNC RATE 60
backdrop on
color backdrop rgb(10,100,100)
autocam off
set global collision off
x#=4000.0:z#=4000.0:angle#=0.0:h#=0.0:distance=100:offset1#=90.0:offset2#=0.0
gosub Setupland
gosub makeobjects
gosub resetcam
do
if inkey$()="+" then distance=distance+1
if inkey$()="-" then distance=distance-1
if inkey$()="1" then offset1#=offset1#+1.0
if inkey$()="2" then offset1#=offset1#-1.0
if inkey$()="3" then offset2#=offset2#+1.0
if inkey$()="4" then offset2#=offset2#-1.0
if inkey$()="r" then gosub reset
gosub printdata
gosub camera_controls
gosub update_camera
gosub control
SYNC
loop
rem -------------ROUTINES--------------------
Setupland:
rem ground textures
rem create texture
cls rgb(0,100,20)
inkcolor#=rgb(255,255,255)
line 0,0,0,250
line 1,1,1,250
line 2,2,2,250
line 0,0,250,0
line 1,1,250,1
line 2,2,250,2
rem line 0,0,250,250
rem line 0,250,250,0
rem next n
get image 2,0,0,250,250
rem Make landscape
landsize=8000:grid=40:mtxrandomize=1
make matrix 1,landsize,landsize,grid,grid
set matrix 1,1,0,0,1,1,1,1
prepare matrix texture 1,2,1,1
randomize matrix 1,mtxrandomize
update matrix 1
return
control:
rem calculate new player position according to speed value
x#=newxvalue(x#,angle#,speed#)
z#=newzvalue(z#,angle#,speed#)
rem drive player
if leftkey()=1 then angle#=wrapvalue(angle#-1)
if rightkey()=1 then angle#=wrapvalue(angle#+1)
if upkey()=1 and speed#<4.0 then speed#=speed#+0.2
if downkey()=1 and speed#>-4.0 then speed#=speed#-0.2
if abs(speed#)<0.1 then speed#=0.0
rem position player
h#=get ground height(1,x#,z#)
position object 10,x#,h#+10,z#
yrotate object 10,angle#
rem calculate object position relative to player
x1#=x#+cos(angle#+offset1#)*-distance
z1#=z#+sin(angle#+offset1#)*distance
rem position object
position object 11,x1#,h#+10,z1#
yrotate object 11,angle#+offset2#
return
reset:
x#=1000.0:z#=1000.0:angle#=0.0:h#=0.0:distance=100:offset1#=90.0:offset2#=0.0
wait 100
return
rem -------CAMERA--------
camera_controls:
mymousez=mousemovez()
if mymousez>0 then camdist=camdist+10
if mymousez<0 then camdist=camdist-10
return
rem camera update
update_camera:
rem Position camera to the back of the character
ca#=wrapvalue(angle#)
cx#=newxvalue(x#,ca#,camdist)
cz#=newzvalue(z#,ca#,camdist)
position camera cx#,cy#+camhgt,cz#
yrotate camera angle#
xrotate camera 30
return
rem camera reset
Resetcam:
set camera range 1,20000
camdist=-250
camhgt=220
return
printdata:
set cursor 0,0
print " Polys=",statistic(1)
print " FPS=",screen fps()
print "--------------------------------------"
print " player world position: x#/z#"
print " x#= ",x#
print " z#= ",z#
print "--------------------------------------"
print " blue object world position: x1#/z1#"
print " x1#=x#+cos(angle#+offset1#)*-distance = ",x1#
print " z1#=z#+cos(angle#+offset1#)*distance = ",z1#
print " object distance= ",distance
print " offset1# = ",offset1#
print "---------------------------------------"
print " player angle (angle#) = ",angle#
print " object angle (angle#+offset2#) = ",angle#+offset2#
print " offset2# = ",offset2#
print "---------------------------------------"
print " + / - = increase / decrease distance"
print " 1 & 2 = change offset1# - object position relative to player"
print " 3 & 4 = change offset2# (object angle)"
print " --------------------------------------"
print " arrow keys to move"
print " r = reset all"
return
makeobjects:
make object cube 10,20
set object 10,1,1,0
scale object 10,100,100,100
make object cube 11,10
set object 11,1,1,0
color object 11,rgb(5,5,200)
scale object 11,100,200,100
xrotate object 11,90
fix object pivot 11
return
end
Cheers
Scorpyo