src_type - entity type to be checked for dxCollisions. dest_type - entity type to be collided with. method - collision detection method. 1: ellipsoid-to-ellipsoid dxCollisions 2: ellipsoid-to-polygon dxCollisions 3: ellipsoid-to-box dxCollisions response - what the source entity does when a collision occurs. 1: stop 2: slide1 - full sliding collision 3: slide2 - prevent entities from sliding down slopes |
Enables dxCollisions between two different entity types. Entity types are just numbers you assign to an entity using dxEntityType. Blitz then uses the entity types to check for dxCollisions between all the entities that have those entity types. Blitz has many ways of checking for dxCollisions, as denoted by the method parameter. However, collision checking is always ellipsoid to something. In order for Blitz to know what size a source entity is, you must first assign an entity radius to all source entities using dxEntityRadius. In the case of collision detection method 1 being selected (ellipsoid-to-ellipsoid), then the destination entities concerned will need to have an dxEntityRadius assigned to them too. In the case of method 3 being selected (ellipsoid-to-box), then the destination entities will need to have an dxEntityBox assigned to them. Method 2 (ellipsoid-to-polygon) requires nothing to be assigned to the destination entities. Not only does Blitz check for dxCollisions, but it acts upon them when it detects them too, as denoted by the response parameter. You have three options in this situation. You can either choose to make the source entity stop, slide or only slide upwards. All collision checking occurs, and collision responses are acted out, when dxUpdateWorld is called. Finally, every time the Collision command is used, collision information is added to the collision information list. This can be cleared at any time using the dxClearCollisions command. See also: dxEntityBox, dxEntityRadius, dxCollisions, dxEntityType, ResetEntity. |
; dxCollisions Example ; ------------------ dxGraphics3D 640,480 dxSetBuffer dxBackBuffer() ; Set collision type values type_ground=1 type_character=2 type_scenery=3 camera=dxCreateCamera() dxRotateEntity camera,45,0,0 dxPositionEntity camera,0,15,-10 light=dxCreateLight() dxRotateEntity light,45,0,0 ; Create cube 'ground' cube=dxCreateCube() dxScaleEntity cube,10,10,10 dxEntityColor cube,0,127,0 dxEntityType cube,type_ground dxPositionEntity cube,0,-5,0 ; Create sphere 'character' sphere=dxCreateSphere( 32 ) dxEntityColor sphere,127,0,0 dxEntityRadius sphere,1 dxEntityType sphere,type_character dxPositionEntity sphere,0,7,0 ; Enable dxCollisions between type_character and type_ground dxCollisions type_character,type_ground,2,2 ; Create cylinder 'scenery' cylinder=dxCreateCylinder( 32 ) dxScaleEntity cylinder,2,2,2 dxEntityColor cylinder,0,0,255 dxEntityRadius cylinder,2 dxEntityBox cylinder,-2,-2,-2,4,4,4 dxEntityType cylinder,type_scenery dxPositionEntity cylinder,-4,7,-4 ; Create cone 'scenery' cone=dxCreateCone( 32 ) dxScaleEntity cone,2,2,2 dxEntityColor cone,0,0,255 dxEntityRadius cone,2 dxEntityBox cone,-2,-2,-2,4,4,4 dxEntityType cone,type_scenery dxPositionEntity cone,4,7,-4 ; Create prism 'scenery' prism=dxCreateCylinder( 3 ) dxScaleEntity prism,2,2,2 dxEntityColor prism,0,0,255 dxEntityRadius prism,2 dxEntityBox prism,-2,-2,-2,4,4,4 dxEntityType prism,type_scenery dxPositionEntity prism,-4,7,4 dxRotateEntity prism,0,180,0 ; Create pyramid 'scenery' pyramid=dxCreateCone( 4 ) dxScaleEntity pyramid,2,2,2 dxEntityColor pyramid,0,0,255 dxEntityRadius pyramid,2 dxEntityBox pyramid,-2,-2,-2,4,4,4 dxEntityType pyramid,type_scenery dxRotateEntity pyramid,0,45,0 dxPositionEntity pyramid,4,7,4 ; Set collision method and response values method=2 response=2 method_info$="ellipsoid-to-polygon" response_info$="slide1" While Not dxKeyDown( 1 ) x#=0 y#=0 z#=0 If dxKeyDown( 203 )=True Then x#=-0.1 If dxKeyDown( 205 )=True Then x#=0.1 If dxKeyDown( 208 )=True Then z#=-0.1 If dxKeyDown( 200 )=True Then z#=0.1 dxMoveEntity sphere,x#,y#,z# dxMoveEntity sphere,0,-0.02,0 ; gravity ; Change collision method If dxKeyHit( 50 )=True method=method+1 If method=4 Then method=1 If method=1 Then method_info$="ellipsoid-to-sphere" If method=2 Then method_info$="ellipsoid-to-polygon" If method=3 Then method_info$="ellipsoid-to-box" EndIf ; Change collision response If dxKeyHit( 19 )=True response=response+1 If response=4 Then response=1 If response=1 Then response_info$="stop" If response=2 Then response_info$="slide1" If response=3 Then response_info$="slide2" EndIf ; Enable dxCollisions between type_character and type_scenery dxCollisions type_character,type_scenery,method,response ; Perform collision checking dxUpdateWorld dxRenderWorld dxText 0,0,"Use cursor keys to move sphere" dxText 0,20,"Press M to change collision Method (currently: "+method_info$+")" dxText 0,40,"Press R to change collision Response (currently: "+response_info$+")" dxText 0,60,"dxCollisions type_character,type_scenery,"+method+","+response dxFlip Wend End |