Well first you need to position a small sphere above your object. Lets say we record that Y position as pos1 as an example. Then move that sphere down until it collides with your object. Now record that Y position as pos2. Then you need to find the distance between these points and record it as Dist so you do pos1-pos2. Then just use the distance from the top point of your object, subtract dist from the y position of pos1 and add that to the object position to get the height of your object. So it would be
dist=pos1-pos2
ObjectHeight=objpos+(pos1-dist)
Heres a function I wrote up to save you some work.
Just call up getobjectheight(obj,x#,z#) and it will return the height at the x and z positions.
function getobjectheight(obj,x#,z#)
set object collision on obj
set object collision to polygons obj
obj2=1
while object exist(obj2)
inc obj2
endwhile
make object sphere obj2,0.05
set object collision on obj2
set object collision to polygons obj2
position object obj2,x#,object position y(obj)+object size Y(obj)+0.1,z#
pos1#=object position y(obj2)
while object collision(obj,obj2)=0 and object position Y(obj2)>object position y(obj)-object size Y(obj)
move object down obj2,0.1
endwhile
pos2#=object position y(obj2)
dist#=pos1#-pos2#
Height#=object position y(obj)+(pos1#-dist#)
delete object obj2
endfunction Height#
Heres a demo.
Rem Project: Dark Basic Pro Project
Rem Created: Sunday, August 15, 2010
Rem ***** Main Source File *****
sync on
sync rate 60
hide mouse
autocam off
make object cone 1,1
set object collision on 1
set object collision to polygons 1
position camera 0,1,-3
point camera 0,0,0
do
text 0,0,"object height: "+str$(getobjectheight(1,0.1,0.0))
turn object right 1,1
sync
loop
function getobjectheight(obj,x#,z#)
set object collision on obj
set object collision to polygons obj
obj2=1
while object exist(obj2)
inc obj2
endwhile
make object sphere obj2,0.05
set object collision on obj2
set object collision to polygons obj2
position object obj2,x#,object position y(obj)+object size Y(obj)+0.1,z#
pos1#=object position y(obj2)
while object collision(obj,obj2)=0 and object position Y(obj2)>object position y(obj)-object size Y(obj)
move object down obj2,0.1
endwhile
pos2#=object position y(obj2)
dist#=pos1#-pos2#
Height#=object position y(obj)+(pos1#-dist#)
delete object obj2
endfunction Height#
My computer can render anything no matter the complexity of it in real time.
The memory is enormous. My computer is unique to everyone else’s. What computer do I have?