I'm using DBPro, and I've made a fairly simple sliding collision code.
It's a bit flickery, as in, when I go onto a point of an object, it jumps to another side, how can I improve my code?
The function:
function slidingcollision(obj,obj2,xstart,xend,zstart,zend)
if object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=>object position x(obj) and object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=>object position z(obj) then position object obj,xstart-1,object position y(obj),object position z(obj)
if object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=<object position x(obj) and object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=>object position z(obj) then position object obj,xend+1,object position y(obj),object position z(obj)
if object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=>object position z(obj) and object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=<object position x(obj) then position object obj,object position x(obj),object position y(obj),zstart-1
if object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=<object position z(obj) and object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=<object position x(obj) then position object obj,object position x(obj),object position y(obj),zend+1
endfunction
And an example:
hide mouse
make object sphere 1,50
make object cube 2,50
position object 1,100,25,100
position object 2,0,25,0
make matrix 1,1000,1000,20,20
do
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),100,150,1,9
if upkey()=1 then move object 1, 0.08
if downkey()=1 then move object 1, -0.08
if leftkey()=1 then move object left 1, 0.08
if rightkey()=1 then move object right 1, 0.08
slidingcollision(1,2,-25,25,-25,25)
cy#=wrapvalue(cy#+mousemovex()*0.08)
acy#=curveangle(cy#,acy#,1)
yrotate object 1,acy#
cx#=wrapvalue(cx#+mousemovey()*0.03)
acx#=curveangle(cx#,acx#,1)
xrotate camera acx#
loop
function slidingcollision(obj,obj2,xstart,xend,zstart,zend)
if object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=>object position x(obj) and object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=>object position z(obj) then position object obj,xstart-1,object position y(obj),object position z(obj)
if object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=<object position x(obj) and object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=>object position z(obj) then position object obj,xend+1,object position y(obj),object position z(obj)
if object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=>object position z(obj) and object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=<object position x(obj) then position object obj,object position x(obj),object position y(obj),zstart-1
if object position z(obj)=>zstart and object position z(obj)=<zend and object position z(obj2)=<object position z(obj) and object position x(obj)=>xstart and object position x(obj)=<xend and object position x(obj2)=<object position x(obj) then position object obj,object position x(obj),object position y(obj),zend+1
endfunction
Help would be nice!
I came, I saw, I programmed!