Your first problem is that you dont have a loop.
- A few things i saw, "until escapekey()=1" the escape key by default will close your program, there is no need for this.
- Also, "wait key" will stop the program completely until a key is pressed, avoid using this; others will say differently; but i prefer not to use this command to often.
- Your sync command should be at the END of your code, the screen should be updated as the last thing, not mid program; this will cause some objects not to show up. I saw that you updated your screen with sync after every print command, you can update your screen all at once just with one sync at the very end of your code.
- I noticed you documented "program starts", "program runs"; this is not needed and will not show up because the program is moving swiftly.
- Another tip is to use sub routines:
unstead of having a huge loop like:
do
if leftkey()=1 then move object 1,3
if rightkey()=1 then move object 1,-3
sync
loop
Thats not very big but with a huge loop it can almost be impossible to find things.
What you can do though is:
do
gosub PlayerMovements
sync
loop
PlayerMovements:
if leftkey()=1 then move object 1,3
if rightkey()=1 then move object 1,-3
return
This way you can now search "playermovements" in DBP and find it easily, and it just allows a much more organized place to work from.
As for your program I couldent figure out exactly what you were trying to do.
If you create any more code I'd be glad to look over it for you.
Cheers,
-Inverted
PS: I messed with your code for a while and i got the object to be in sight, although it probably isnt what your looking for, sorry if you couldent help you on this one:
hide mouse
sync on
sync rate 60
set window on
set window size 800,600
rem designing world
make object box 1,600,20,400
color object 1,rgb(20,200,20)
position object 1,0,550,0
set object collision to boxes 1
make object box 2,100,20,100
color object 2,rgb(200,20,20)
position object 2,0,400,0
set object collision to boxes 2
make object box 100,10,40,10
color object 100,rgb(20,20,200)
position object 100,0,100,0
set object collision to boxes 100
position camera 400,500,-100
point camera 400,300,0
autocam off
rem setting parameters
gravity#=0.2
freespeed=5
onground=0
thrust#=5
jump=0
plrS#=0
do
rem main program loop
plrY#=object position y(100)
plrX#=object position x(100)
plrZ#=object position z(100)
rem free fall
if onground=0 and jump=0
if plrS#<freespeed
inc plrS#,gravity
inc plrY#,plrS#
else
inc plrY#,freespeed
endif
endif
rem collision detection
if object collision(100,0)>0
collobject = object collision(100,0)
set cursor 10,60:print "colliding with : " ; collobject
if plrX#<object position y(collobject) `checking if plr is to the left or right
onleft=1
else
onleft=0
endif
if plrY#<object position y(collobject) `checking if plr is on top or below
ontop=1
else
ontop=0
endif
if plrZ#<object position z(collobject) `checking if plr is in front or behind
infront=1
else
infront=0
endif
endif
rem avoid collision
if ontop=1
dec plrY#,2
onground=1
plrS#=0
endif
if onleft=1
dec plrX#,2
else
if onleft=0
inc plrX#,2
endif
endif
if infront=1
dec plrZ#,2
else
if infront=0
inc plrZ#,2
endif
endif
rem Player movement
if leftkey()=1 then dec plrX#
if rightkey()=1 then inc plrX#
if upkey()=1 and onground=1
onground=0
jump=1
endif
rem jump code
if jump=1
if plrS#>0
inc plrS#,thrust
dec plrY#,plrS#
else
jump=0
plrS#=0
endif
endif
rem position player
position object 100,plrX#,plrY#,plrZ#
sync
loop
Come take a look!