Well here is your code but working:
make object cube 1,5
position object 1,10,0,40
make object box 2,5,2,5
position object 2,0,0,20
set global collision on
life=100
sync on
sync rate 60
do
control camera using arrowkeys 0,0.5,0.5
x#=newxvalue(camera position x(),camera angle y(),5)
y#=camera position y()-3
z#=newzvalue(camera position z(),camera angle y(),5)
position object 2,x#,y#,z#
rotate object 2,camera angle x(),camera angle y(),camera angle z()
if object hit(1,2)=1
life=life-50
endif
if life=0
end
endif
sync
loop
Here is my own collision function using Sparky's dll:
rem =========================================================================================
rem === RunCollision() ===
rem =========================================================================================
function RunCollision(ColObj,LvlObj,MaxDiameter#,MinDiameter#,Height#,ReturnFlag)
rem State flags
OnFloor=0
Hit=0
rem Store ColObj position
x#=object position x(ColObj)
y#=object position y(ColObj)
z#=object position z(ColObj)
rem Collision
y1#=sc_intersectobject(LvlObj,x#,y#,z#,x#,y#-50,z#)
if y1#>0.0 and y1#<(Height#/2)
y#=y#+((Height#/2)-y1#)
OnFloor=1
Hit=1
endif
y2#=sc_intersectobject(LvlObj,x#,y#,z#,x#,y#+50,z#)
if y2#>0.0 and y2#<(Height#/2)
if OnFloor=0
y#=y#-((Height#/2)-y2#)
OnFloor=2
Hit=1
else
OnFloor=3
Hit=1
endif
endif
for ay=0 to 315 step 45
i#=sc_intersectobject(LvlObj,x#,y#-(Height#/4.0),z#,newxvalue(x#,ay,50),y#-(Height#/4.0),newzvalue(z#,ay,50))
if i#>0.0 and i#<(MinDiameter#/2)
x#=newxvalue(x#,ay,i#-(MinDiameter#/2))
z#=newzvalue(z#,ay,i#-(MinDiameter#/2))
Hit=1
endif
next ay
for ay=0 to 315 step 45
i#=sc_intersectobject(LvlObj,x#,y#+(Height#/2.0),z#,newxvalue(x#,ay,50),y#+(Height#/2.0),newzvalue(z#,ay,50))
if i#>0.0 and i#<(MinDiameter#/2)
x#=newxvalue(x#,ay,i#-(MinDiameter#/2))
z#=newzvalue(z#,ay,i#-(MinDiameter#/2))
Hit=1
endif
next ay
for ay=0 to 315 step 45
i#=sc_intersectobject(LvlObj,x#,y#,z#,newxvalue(x#,ay,50),y#,newzvalue(z#,ay,50))
if i#>0.0 and i#<(MaxDiameter#/2)
x#=newxvalue(x#,ay,i#-(MaxDiameter#/2))
z#=newzvalue(z#,ay,i#-(MaxDiameter#/2))
Hit=1
endif
next ay
rem Update object
position object ColObj,x#,y#,z#
rem Set return value
if ReturnFlag=0
ReturnValue=OnFloor
else
ReturnValue=Hit
endif
endfunction ReturnValue
An explanation of the inputs:
ColObj = The moving object id
LvlObj = The object to collide with
MaxDiameter# = The dimater of the object at the middle
MinDiameter# = The diameter of the object at the top
Height# = The height of the object (can be got through object size y())
ReturnFlag = If set to 0 then the function will return a 1 if the object hits the floor or a 2 if it hits the ceiling or a 0 if it hits neither. If set to 1 then the function will return a 1 if a collision occurs or a 0 if no collision occurs.