It prob won't work well with both objects moving,but try it and do tell..
make object sphere 1,1
make object sphere 2,1
color object 2,rgb(255,0,0)
sync on:sync rate 70
move object 2,4
set camera range 0.001,100
do
oldx# = object position x(1)
oldz# = object position z(1)
oldy# = object position y(1)
`movement contrl
rotate object 1,0,wrapvalue(object angle y(1)+(mousemovex()/2)),0
if upkey()=1 then move object 1,.1
if downkey()=1 then move object 1,-.1
`coll
col_slide(1,2,1)
`cam
position camera newxvalue(object position x(1),object angle y(1),-2),object position y(1)+.6,newzvalue(object position z(1),object angle y(1),-2)
point camera object position x(1),object position y(1),object position z(1)
`debug
text 10,10,str$(angle#)
sync
loop
function dist3d(obj1,obj2)
x1# = object position x(obj1)
y1# = object position y(obj1)
z1# = object position z(obj1)
x2# = object position x(obj2)
y2# = object position y(obj2)
z2# = object position z(obj2)
temp = make vector3(1)
set vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
dist# = abs(length vector3(1))
temp = delete vector3(1)
endfunction dist#
`sliding collision in the XZ plane
`obja is the object which will be repositioned
function col_slide(obja,objb,size#)
dist# = dist3d(obja,objb)
if dist# < size#
`we take the new position of our object A ,which is in object B's sphere
`and get new coors a bit farther from the center of object B's sphere
`this is done using the newvalue commands and the yangle (angle#)
`that objectA would have if pointing towards the center of objectB's sphere
`its done using vectors. since only the yangle is found , this sliding collision
`is only on the XZ plane
two = make vector3(2)
three = make vector3(3)
set vector3 2,object position x(objb)-object position x(obja),0,object position z(objb)-object position z(obja)
set vector3 3,0,0,1
angle# = acos((dot product vector3(2,3))/(length vector3(2))*abs(length vector3(3)))
if object position x(objb)-object position x(obja) < 0 then angle# = 360-angle#
two = delete vector3(2)
three = delete vector3(3)
`here we use the newvalue commands
position object obja,newxvalue(object position x(obja),angle#,-1*(size#-dist#)),oldy#,newzvalue(object position z(obja),angle#,-1*(size#-dist#))
endif
endfunction
"hello my brother. hello and goodbye."
-black man on drugs outside a big white house