Hi all. It's been about 7 or 8 years since I last worked with DB & DB Pro; after seeing the DB Studio Bonanza deal I'm happy to be back.
I've been trawling through the forums for a while and finally have a bit of a 3rd person test world. This code isn't very good (it's just meant as some foundation code to test with) but there's some unexpected behavior I'd like to ask some seasoned dev's to advise on.
The following produces a matrix, populates it with a player, a non-player character and some trees. The NPC is supposed to (constantly) move towards the player, however it's motion appears to be stuck in the 'X' plane.
EDIT: There's a typo that I missed several times while looking through the code... I'll leave this here if anyone wants it. Comments on any other parts of the code would still be most welcome.
Rem Project: matrix4
Rem Created: Monday, February 13, 2012
Rem
Rem Simple 3rd person test, based in part on http://forums.thegamecreators.com/?m=forum_view&t=48681&b=7
Rem
Rem ***** Main Source File *****
debug = 1
fullscreen = 0
if fullscreen > 0 then set window off
sync on : sync rate 60
hide mouse : autocam off
` do world setup
init()
` main loop
moveSpeed# = 0.3
do
` grab and display some core info
fps = screen fps()
px# = object position x(1)
py# = object position y(1)
pz# = object position z(1)
pya# = object angle y(1)
if debug > 0
text 0,0, "FPS: " + str$(fps)
text 0,10, "Position: " + str$(px#) + " x " + str$(pz#)
text 0,20, "Height: " + str$(py#)
text 0,30, "Heading: " + str$(pya#)
endif
` handle heading w mouse
mmx = mousemovex() : mmy = mousemovey()
if (mmx < 0) then pya# = wrapvalue(pya# - 1.5)
if (mmx > 0) then pya# = wrapvalue(pya# + 1.5)
` handle heading w kybd
if inkey$() = "a" then pya# = wrapvalue(pya# - 1.5)
if inkey$() = "d" then pya# = wrapvalue(pya# + 1.5)
yrotate object 1, pya#
yrotate object 2, pya#
` handle movement
direction = 0
moving = 0
if inkey$() = "w"
direction = -1
moving = 1
endif
if inkey$() = "s"
direction = 1
moving = 1
endif
` reposition player
py_ground# = get ground height(1, px#+500, pz#+500)
position object 1, px#,py_ground#,pz#
position object 2, px#,py_ground#,pz#
move object 1, direction * moveSpeed#
move object 2, direction * moveSpeed#
` display idle or moving model
if moving > 0
hide object 1
show object 2
else
hide object 2
show object 1
endif
` update camera
camHeight# = py# + 0.5
if camHeight# < 5 then camHeight# = 5.0
if camHeight# > 35 then camHeight# = 35.0
set camera to follow px#,py#,pz#, pya#-180, 10, camHeight#, 10, 1
` make npc look at and follow player
skelx# = object position x(50)
skeyz# = object position z(50)
skely# = get ground height(1, 500+skelx#, 500+skelz#)
position object 50, skelx#, skely#, skelz#
point object 50, px#, py#, pz#
move object 50, moveSpeed# * 0.75
yrotate object 50, wrapvalue(object angle y(50)-180)
sync
loop
rem SUBROUTINES and FUNCTIONS
` initialize game world and objects
` all models except the trees are from DarkMATTER
` tree model build with Tree Magik
function init()
` matrix
load image "Textures\grass1.jpg", 1
make matrix 1, 1000, 1000, 20, 20
randomize matrix 1, 10
prepare matrix texture 1,1,1,1
update matrix 1
position matrix 1, -500,0,-500
`player
load object "Models\People\Knight\L-Knight-Idle.X", 1
scale object 1, 200,200,200
position object 1, 0,0,0
loop object 1
yrotate object 1, 180
load object "Models\People\Knight\L-Knight-Move.X", 2
scale object 2, 200,200,200
position object 2, 0,0,0
loop object 2
yrotate object 2, 180
` skybox
load object "Models\Skyboxes\sky01\sky01.X", 3
scale object 3, 10000,10000,10000
position object 3, 0,0,0
` trees
load object "Models\Foliage\tree1.x\lo_tree1.x", 4
scale object 4, 50, 50, 50
position object 4, 5,0,5
set object transparency 4, 2
yrotate object 4, rnd(360)
for i = 5 to 30
instance object i, 4
set object transparency i, 2
tx# = 500-rnd(1000)
tz# = 500-rnd(1000)
th# = get ground height(1, tx#+500, tz#+500)
position object i, tx#, ty# + 2, tz#
scale# = 30 + rnd(20)
scale object i, scale#, scale#, scale#
yrotate object i, rnd(360)
next i
` npc's
skelx# = 100
skelz# = 100
skely# = get ground height(1, 500+skelx#, 500+skelz#)
load object "Models\People\Bones\L-Bones-Idle.X", 50
scale object 50, 200,200,200
position object 50, skelx#, skely#, skelz#
loop object 50
` setup some fog
fog on
fog distance 750
fog color rgb(127,127,127)
endfunction
- psema4