CreateEntityBody(2,1) CreateEntityBody(4,1) result = EntityCollide(2,4) d=1If result > 0 d=d+1EndIf If d <=1 CameraBackColor(0,#Blue) EndIf If d >=2 CameraBackColor(0,#Red) d=0 EndIf FreeEntityBody(2)FreeEntityBody(4)
createentitybody(1,#PB_entity_staticbody)
CreateEntityBody(2,1) CreateEntityBody(4,1) result = EntityCollide(2,4)
CreateEntityBody(2,1)CreateEntityBody(4,1)if EntityCollide(2,4) > 0 CameraBackColor(0,#Blue)else CameraBackColor(0,#Red)EndIfFreeEntityBody(2)FreeEntityBody(4)
I needed to check for 5 orb collisions and 5 food collisions hence 10 checks per level per frame . so that's 350 lines of collision checking for each level and there were 12 levels . Hence 350 lines per level times 12 .
;list with dim arrays :global entitiescount%dim entitykind%(100) ;integer constant (cplayer or corb or cfood)dim entitymesh(100) ;referencedim entitylife#(100) ;float;list with custom type :type entity field kind% ;integer constant (cplayer or corb or cfood) field mesh ;reference field life# ;floatend type
objID=2objID2=8function checkCollision4(objID as integer,objID2 as integer) local width# as floatlocal height# as floatlocal depth# as floatlocal x# as floatlocal y# as floatlocal z# as floatlocal start_x# as floatlocal start_y# as floatlocal start_z# as floatlocal end_x# as floatlocal end_y# as floatlocal end_z# as floatlocal object_Hit as integer //this checks for colliion between an object with any other object and returns its idwidth#=(GetObjectMeshSizeMaxX(objID,1)-GetObjectMeshSizeMinX(objID,1))/2 height#=(GetObjectMeshSizeMaxX(objID,1)-GetObjectMeshSizeMinX(objID,1)) depth#=(GetObjectMeshSizeMaxX(objID,1)-GetObjectMeshSizeMinX(objID,1))/2 x#=getObjectWorldX(objID)y#=GetObjectWorldY(objID)z#=getObjectWorldZ(objID) // calculate the start of the ray caststart_x# = x#-width#start_y# = y#+height#start_z# = z#-depth#// calculate the end of the ray castend_x# = x#+width# end_y# = y#-height#end_z# = z#+depth# // determine which object has been hitobject_Hit = ObjectRayCast(objID2,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)endfunction object_Hitif checkcollision4(2,8)=1 deleteobject(8) resettimer() playsound(1) key4=1 key=key+1 endif