first, please don't make us download a file when it's only ~20 lines of code (downloads are usually attached if you think an exe is running improperly and would like others to test on their systems, there is media essential to the app, or there is enough code to justify it (yeah, that's relative/a judgement call, but it's somewhere way above ~20 lines of code)
instead (your code):
width = desktop width()
height = desktop height()
set display mode width, height, 32, 1
set window off
sync on
sync rate 60
make matrix 1, 1000, 1000, 100, 100
make object cube 1, 10
do
gosub movement
set camera to follow object position x(1), object position y(1), object position z(1), object angle y(1) - 180, 30, 20, 5, 1
sync
LOOP
movement:
if upkey() = 1 then speed# = 2
if downkey() = 1 then speed# = -2
if leftkey() = 1 then turn object left 1, 3
if rightkey() = 1 then turn object right 1, 3
move object 1, speed
return
2nd, you're moving the object at the value of
speed, not
speed#. you're setting
speed# but since you never set
speed, it will remain 0. it's a typo, i'm sure, but know there's a difference in the 2 variables which is the root of your movement issue.
3rd, i'd avoid the 'automatic' commands as they'll rarely do precisely what you're looking for, and some of them are buggy.
in this case,
set camera to follow is doing what it's intended to do but not what you'd expect from a more-familiar 3rd-person perspective/camera.
and, the use of
turn commands should be avoided as un-reliable in dbpro (the combination of both, in your code, is causing the bug in
turn to appear)
instead, take conrol of player controls
and the camera by modifying your code similar to:
width = desktop width()
height = desktop height()
set display mode width, height, 32, 1
`set window off <- REM'd as not necessary
autocam off ` <- added as best practice
sync on
sync rate 60
make matrix 1, 1000, 1000, 100, 100
update matrix 1 `added as best practice
make object cube 1, 10
do
gosub _move:
gosub _cam:
sync
loop
_move:
speed# = (upkey()-downkey())*2.0
turn# = (rightkey()-leftkey())*3.0
yrotate object 1, wrapvalue(object angle y(1)+turn#)
move object 1, speed#
return
_cam:
x# = object position x(1) : y# = object position y(1) : z# = object position z(1) : ya# = object angle y(1)
position camera x#, y#+20.0, z#
yrotate camera ya#
move camera -40.0
return
this doesn't include the inherent
smooth and
collision functionality of the autocam
set camera to follow-options but you can add those yourself in the same 'take control of everything' fashion.
(frankly, most don't use the auto-collision commands so you'd probably go a different route there, anyway, at some point, soon).
the above is offered as a starting point to build upon (and i'm pretty sure there is some more-exhaustive camera code out there if you search for it a bit).
come back with any other questions, and good luck
add: you'll notice that i only move the cube when up/down is pressed. since, in your code, you never set speed/speed# to zero, the cube moves constantly (once either up or down is pressed). i didn't know if that was intentional so i went with what my personal habit and instinct
Virtual Nomad @ California, USA . DBPro V7.7
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit