Okay, you are actually using a sphere placed at the camera's location to provide collision. Yet, you want to have the top of the box to be at eyelevel, correct?
When it first runs, the sphere falls down on top of the box. I moved the sphere over some, so that it will fall down to rest on the red box.
I then re-sized the box so that it's height is consistent with the sphere. When sc_getcollisionslidey() is obtained, I added half of the collision sphere's height to it, so that the camera is on top of it. The result is that the camera is at the height of the box.
set display mode 1280,800,32
sync on:sync rate 60
`maximise window get dbpro window()
radius# = 5.0
make object sphere 1,radius#*2.0
position object 1,20,10,20
sc_setupobject 1,0,1
remstart
load object "Assets\models\building.dbo",2
load effect "lightmap.fx",1,1
set object effect 2,1
sc_setupcomplexobject 2,1,4
remend
make object box 2,100,0.1,100
color object 2,rgb(255,0,0)
set object emissive 2,rgb(255,0,0)
sc_setupobject 2,1,2
make object box 3,radius#,radius# * 2,radius# : `20,40,20
position object 3,0,radius#,0
color object 3,rgb(0,0,255)
set object emissive 3,rgb(0,0,255)
sc_setupobject 3,1,2
do
oldx# = object position x(1)
oldy# = object position y(1)
oldz# = object position z(1)
angy# = object angle y(1)
if onfloor = 1
if spacekey() = 1 then vy# = vy# + 1.0
endif
vy# = vy# - 0.05
if keystate(17)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
if keystate(32)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if keystate(31)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
xrotate object 1,object angle x(1) + mousemovey()/3
yrotate object 1,object angle y(1) + mousemovex()/3
x# = oldx# + vx#
y# = oldy#+ vy#
z# = oldz# + vz#
text 0,0,str$(onfloor)
if sc_spherecastgroup( 1, oldx#, oldy#, oldz#, x#, y#, z#, radius#, 0 ) > 0
x# = sc_getcollisionslidex()
y# = sc_getcollisionslidey()
z# = sc_getcollisionslidez()
ny# = sc_getcollisionnormaly()
if ny# > 0.7
y# = sc_getstaticcollisiony()
else
x# = sc_getcollisionslidex()
y# = sc_getcollisionslidey()
z# = sc_getcollisionslidez()
if ny# < -0.7
vy# = -0.05
endif
endif
if ny# > 0.7
onfloor = 1
vy# = 0
else
onfloor = 0
endif
else
onfloor = 0
endif
if sc_spherecastgroup( 1, oldx#, oldy#, oldz#, x#, y#, z# , radius#, 0 ) > 0
x# = sc_getcollisionslidex()
y# = sc_getcollisionslidey()
z# = sc_getcollisionslidez()
endif
position object 1,x#,y#,z#
sc_updateobject 1
vx# = 0 : vz# = 0
position camera x#,y# + (object size y(1) * .5),z#
set camera to object orientation 0,1
sync
loop
Hope this helps.
LB