Hi Still Remains, welcome to the forums!
Your code looks in pretty good shape, just one or two minor goofs. To answer your questions:
1)when you move cube 1 forwards and it bumps into the "wall", you told cube 1 to move backwards until it was no longer colliding. Now, if you are moving backwards and then you bump into the wall, you still move backwards until no collision occurs. Result? The cube moves straight through the wall!
2) You also mentioned a problem with the cube 'sinking into the wall' when you rotate it. I could be mistaken, but I believe your collision box does not rotate with the box (in other words, DB is checking for a collision between the cube and the wall as if neither had been rotated).
So, here's your code back with a few modifications to solve the problems:
sync on
rem Player Creation
make object cube 1,50
color object 1, rgb(155,0,155)
make object collision box 1,-40,-40,-40,40,40,40,0
rem Level Creation
make object box 2,5000,10,5000
position object 2,0,-55,0
color object 2, rgb(0,255,0)
rem Object Creation
make object box 5,250,200,10
position object 5,0,100,500
make object collision box 5,-125,-100,-5,125,50,5,0
rem Declare Constant Variables
MySpeed = 10
sync
MainSection:
rem Main Loop Begin
do
rem HUD
center text 320,400,"Press the up arrow to move forward | Press the left and right arrows to turn"
rem Store old positions
angle# = object angle y(1)
rem I added this, but I don't think its needed
`oldposx#=object position x(1)
`oldposy#=object position y(1)
`oldposz#=object position z(1)
rem Player Movement
if upkey()=1 then move object 1,MySpeed
if downkey()=1 then move object 1,0-MySpeed
if rightkey()=1 then angle#=wrapvalue(angle#+5)
if leftkey()=1 then angle#=wrapvalue(angle#-5)
yrotate object 1,angle#
rem Get current object position
posx#=object position x(1)
posy#=object position y(1)
posz#=object position z(1)
rem Handle sliding collision for player object with other objects
position object 1,posx#,posy#,posz#
if object collision(1,0)>0
dec posx#,get object collision x()
dec posy#,get object collision y()
dec posz#,get object collision z()
endif
position object 1,posx#,posy#,posz#
rem Camera Mechanics
set camera to follow posx#,posy#,posz#,object angle y(1),250,posy#+150,10,1
point camera posx#,posy#,posz#
sync
rem Main Loop End
loop
For Problem 2, I've just enlarged the collision box. Somewhere between 35 and 40 seems ideal, I just haven't been able to fine tune it any better (I tried adjusting the flag at the end from 0 to 1, but it disabled collision entirely).
Problem 1 needs a more in-depth look. There's probably a better way of doing this, but after moving your object you store the position. If a collision occurs, you call "get object collision x()" for X, Y and Z. The help files say this returns sliding data - I think it actually tells you how far into the wall your cube has been pushed in. For example, if half the cube is inside the wall then these commands will tell you what you must do to the X, Y and Z coordinates of the object in order to move it back outside the wall. So, we decrease the position of the opbject by the specified amount, reposition the object, and on screen it looks as though the cube never enters the wall - the wall has become a solid object!
Hope this helps!
"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."