Yes, that works nicely.
I`m still not convinced its a bug (the original code), in that one you were telling the camera where to be, if the system detected that the new position was in collision with an object it would leave it where it was. But your position numbers would still be at the new position, so when the position you set the camera to was again outside the object the camera correctly moved to that position.
In the new code I suspect that the system simply resets the camera position to the last point before it collided, so it never gets set to a point on the other side of the object.
Sorry I don`t have a code snippet that can be easily untangled from the rest of the game its in. I can tell you that in DB (which had no automatic camera collision) I used to use static collision to set up areas where the camera should not be, you don`t even need an object to detect a collision with a static area, just use the command 'get static collision hit(,,,,,,,,,,,)' on any rectangular area (IE the surrounding area of the camera).
Here is a code snippet (OK I lied.... actually, I just went off and did this), its basically your original code with static collision used instead of automatic camera collision. I preferred your original code as it tracked a point (like a 3rd person game) I added a sphere to act as the player (it does not collide, but it could) and I smoothed the camera motion, as it looks more professional.
set global collision on
`automatic camera collision 0,30,1
`set object collision to boxes 1
` Make a static collision box that fits around the cube
`(note you could remove the cube and it would still collide)
make static collision box 500-25,25-25,700-25,500+25,25+25,700+25
rem adjust this for start camera position
x#=500
z#=500
` this is just to avoid the camera colliding as soon as it appears
cx#=newxvalue(x#,180,10)
cz#=newzvalue(z#,180,10)
cy#=get ground height(1,cx#,cz#)+50.0
oldx# = cx# : oldy# = cy# : oldz# = cz#
rem Begin loop
do
rem printing
ink rgb(250,58,240),0
SET TEXT SIZE 20
print "FPS ";screen fps()
set cursor 5,10
rem Contol camera with mouse
pitch#=wrapvalue(pitch#+mousemoveY())
xrotate camera pitch#
a#=wrapvalue(a#+mousemovex())
yrotate camera a#
if mouseclick()=1 then x#=newxvalue(x#,a#,1) : z#=newzvalue(z#,a#,1)
if mouseclick()=2 then x#=newxvalue(x#,a#,-1) : z#=newzvalue(z#,a#,-1)
rem Position camera
ca#=wrapvalue(curveangle(a#,ca#,12.0))
cx#=curvevalue(oldx#,newxvalue(x#,wrapvalue(ca#+180),30),1.02)
cz#=curvevalue(oldz#,newzvalue(z#,wrapvalue(ca#+180),30),1.02)
cy#=get ground height(1,cx#,cz#)+50.0
` Note this pretends the camera is 10 units square
if get static collision hit(oldx#-5,oldy#-5,oldz#-5,oldx#+5,oldy#+5,oldz#+5,cx#-5,cy#-5,cz#-5,cx#+5,cy#+5,cz#+5) = 1
` this position is in collision so put camera at its old position
cx# = oldx# : cy# = oldy# : cz# = oldz#
` here would be a good place to put clever stuff like camera sliding,
` or a time count, after which you reset the camera
endif
position camera 0,cx#,cy#,cz#
yrotate camera wrapvalue(ca#)
` store the current (not colliding) position
oldx# = cx# : oldy# = cy# : oldz# = cz#
` position our player
position object 2,x#,cy#-50,z#
rem Syncronise
Sync
rem End loop
loop