Posted: 26th Mar 2009 18:18
i am rather new to DB as i am sure you can tell with the state of my code. i have a problem with setting up my collisions with the user and the wall. i have successfully set it up for wall (1) the wall to the left however putting in t same code for the other 3 walls doesnt work.
does anyone have any ideas.
please find code below
Sync On
Hide Mouse
Randomize Timer()
`load User
` load object "n:\media\animations\idle.x",9 : append object "n:\media\animations\walk.x",9,100
` yrotate object 9,180 : fix object pivot 9
make object sphere 9,50
color object 9,rgb(255,255,0)
position object 9, 100, 100, 100
`makes floor
make object box 5, 1080, 10, 1080
position object 5, 540, -5, 540
if Tex=0
color object 5,rgb(100, 100, 100)
else
texture object 5, 1
endif
scale object texture 5, 17, 17
`********************************makes outer walls*********************************
make object box 1, 5, 100, 1080
position object 1, 0, 50, 530
color object 1, rgb(155, 40, 20)
scale object texture 1, 17, 1
make object box 2, 5, 100, 1080
position object 2, 1075, 50, 535
color object 2, rgb(155, 40, 20)
scale object texture 2, 17,1
make object box 3, 1070, 100, 5
position object 3, 535, 50, 0
color object 3, rgb(155, 40, 20)
scale object texture 3, 17, 1
make object box 4, 1080, 100, 5
position object 4, 535, 50, 1075
color object 4, rgb(155, 40, 20)
scale object texture 4, 17, 1
`***************************************************************************
`loop 3d object animation from 0 to 20
` loop object 9,0,20 : set object speed 9,10
`Store old position
oldx#=x#
oldz#=z#
olda#=a#
`
x#= 100
z# = 100
sync on
do
`modify character angle based on left/right keys
stage=0
if leftkey()=1 then a#=a#-8.0
if rightkey()=1 then a#=a#+8.0
a#=wrapvalue(a#)
` modify character position based upon
if upkey()=1 then x#=newxvalue(x#,a#,3) : z#=newzvalue(z#,a#,3)
stage=1
if downkey()=1 then x#=newxvalue(x#,a#,-3) : z#=newzvalue(z#,a#,-3)
stage=1
`**************************sets object collsions****************************
obx = object position x(9)
oby = object position y(9)
obz = object position z(9)
`if collision move 1 space away
if object hit(9,1)>0
x#=obx +1
z#=obz +1
a#=oby
endif
if object hit(9,2)>0
x#=obx +1
z#=obz +1
a#=oby
endif
if object collision(9,3)>0
x#=obx +1
z#=obz +1
a#=oby
endif
if object collision(9,4)>0
x#=obx +1
z#=obz +1
a#=oby
endif
if object hit(9,2) = 1
x#=obx +1
z#=obz +1
a#=oby
endif
`***************************************************************************
`uppdates character position and angle
position object 9,x#,0.0,z#
yrotate object 9,a#
`get new camera position and store in cZ# and cX#
cZ# = newzvalue(Z#, aY-180,100)
cX# = newxvalue(X#, aY-180,200)
plx=object position x(9)
ply=object position y(9)
plyy=ply+500
plz=object position z(9)
`position camera
position camera plx, plyy, plz
`point the camera at the player object
point camera plx, ply, plz
sync
loop