ok. the source of the code that i based this on was written by jesTicular and modified by sjakie. i found it in a pathfinding program that they were working on. anyways, i found that it only worked well with a matrix and involved lots of moving and turning of objects and stuff. i greatly simplified it, using raycasting. now it works with normal .x objects, and is alot simpler.
however, you need nuclear glory(wich, if you are using a .x object for your terrain, i assume you would have.) here it is:
REM 3d pointer movement and collision
SCH=screen height()/2
SCW=screen width()/2
move# =(mousex()-SCW)/4
move2# =(mousey()-SCH)/4
depth=100
width=move#
LRang=atanfull(width,depth)
depth=100
width=move2#
UDang=atanfull(width,depth)
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
newx#=newxvalue(camera position x(), camera angle y()+LRang,1000)
newy#=newyvalue(camera position y(), camera angle x()+UDang,1000)
newz#=newzvalue(camera position z(), camera angle x()+UDang, 1000)
rHit = RayIntersectTypePRO(WORLD_MESH, TYPE_NGC_MESH, camx#, camy#, camz#, newx#, newy#, newz#)
if rHit
rem Gets the positions the ray intersected the object
hitX# = RayHitPosPRO("X")
hitY# = RayHitPosPRO("Y")
hitZ# = RayHitPosPRO("Z")
rem Gets the normals of the surface that was intersected
hitNX# = RayHitNormPRO("X",0)
hitNY# = RayHitNormPRO("Y",0)
hitNZ# = RayHitNormPRO("Z",0)
rem Push the hit positions away from the surface a bit
hitX# = hitX# + (hitNX# * 0.20)
hitY# = hitY# + (hitNY# * 0.20)
hitZ# = hitZ# + (hitNZ# * 0.20)
rem position the mouse pointer
position object 500, hitX#, hitY#, hitZ#
endif
rem pointer collision
position object 500, object position x(500),object position y(500)+600,object position z(500)
px#=object position x(500)
py#=object position y(500)
pz#=object position z(500)
rHit = RayIntersectTypePRO(WORLD_MESH, TYPE_NGC_MESH, px#, py#, pz#, px#, py#-800, pz#)
if rHit
rem Gets the positions the ray intersected the object
hitX# = RayHitPosPRO("X")
hitY# = RayHitPosPRO("Y")
hitZ# = RayHitPosPRO("Z")
rem Gets the normals of the surface that was intersected
hitNX# = RayHitNormPRO("X",0)
hitNY# = RayHitNormPRO("Y",0)
hitNZ# = RayHitNormPRO("Z",0)
rem Push the hit positions away from the surface a bit
hitX# = hitX# + (hitNX# * 0.20)
hitY# = hitY# + (hitNY# * 0.20)
hitZ# = hitZ# + (hitNZ# * 0.20)
rem position the mouse pointer
position object 500, hitX#, hitY#, hitZ#
endif
object 500 is what i used as the 3d mouse object, but you can replace that with whatever.
Your Head A-Splode