Blitz3D+ Command Reference

Collisions source_type,destination_type,method,response

Parameters

source_type - collision type of the moving entities to be checked

destination_type - collision type of the entities they collide with

method - collision detection method
1: ellipsoid-to-ellipsoid
2: ellipsoid-to-polygon
3: ellipsoid-to-box

response - what the source entity does when a collision occurs
1: stop
2: slide - full sliding collision
3: slide, but never slide down slopes

Description

Registers a collision pair: entities of one collision type will collide with entities of another.

This command only sets up the rule - the actual checking and response happen inside UpdateWorld, each time you call it. Collision types are just numbers you invent and hand out with EntityType: give the player type 1, the scenery type 2, then Collisions 1,2,2,2 makes the player slide along the level like a proper walking character.

Collision checking is always ellipsoid-to-something, so every source entity needs an EntityRadius. What the destination needs depends on the method: ellipsoid-to-ellipsoid (1) needs destinations with an EntityRadius too; ellipsoid-to-box (3) needs destinations with an EntityBox; ellipsoid-to-polygon (2) needs nothing extra - the destination's actual mesh triangles are used.

The response decides what the mover does on contact: stop dead (1), slide along the obstacle (2), or slide without ever being pushed down a slope (3).

The pair is one-way: sources are tested as they move, so give the moving things the source role. An entity that did not move this step triggers no collisions of its own - though it still records being hit by movers.

Registering the same source/destination pair again does nothing: the first method and response stick until you wipe the registered pairs with ClearCollisions and register afresh.

See also: EntityType, EntityRadius, EntityBox, UpdateWorld, ClearCollisions, CountCollisions.

Example

; Collisions Example
; ------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; Collision type ids
type_player=1
type_scenery=2

; NOTE: fixed overhead camera - the arrow keys steer the PLAYER, not the camera
camera=CreateCamera()
PositionEntity camera,0,13,-13
RotateEntity camera,45,0,0

light=CreateLight()
RotateEntity light,60,30,0

floor=CreatePlane()
EntityColor floor,70,110,70

; The player ball is the collision SOURCE, so it needs an ellipsoid radius
player=CreateSphere()
EntityColor player,220,60,60
PositionEntity player,0,1,-4
EntityRadius player,1
EntityType player,type_player

; Three crates. They are given radius AND box data so that every collision
; method has the information it needs on the destination side.
crate1=CreateCube()
ScaleEntity crate1,1.2,1.2,1.2
PositionEntity crate1,-4,1.2,4
EntityColor crate1,200,160,60
EntityType crate1,type_scenery
EntityRadius crate1,1.7
EntityBox crate1,-1.2,-1.2,-1.2,2.4,2.4,2.4

crate2=CreateCube()
ScaleEntity crate2,1.2,1.2,1.2
PositionEntity crate2,0,1.2,4
EntityColor crate2,200,160,60
EntityType crate2,type_scenery
EntityRadius crate2,1.7
EntityBox crate2,-1.2,-1.2,-1.2,2.4,2.4,2.4

crate3=CreateCube()
ScaleEntity crate3,1.2,1.2,1.2
PositionEntity crate3,4,1.2,4
EntityColor crate3,200,160,60
EntityType crate3,type_scenery
EntityRadius crate3,1.7
EntityBox crate3,-1.2,-1.2,-1.2,2.4,2.4,2.4

method=2
response=2
method_name$="ellipsoid-to-polygon"
response_name$="slide"

While Not KeyDown(1)

    ; Arrow keys steer the player ball
    If KeyDown(200) Then MoveEntity player,0,0,0.1
    If KeyDown(208) Then MoveEntity player,0,0,-0.1
    If KeyDown(203) Then MoveEntity player,-0.1,0,0
    If KeyDown(205) Then MoveEntity player,0.1,0,0

    ; M cycles the collision method, R cycles the response
    If KeyHit(50)
        method=method+1
        If method>3 Then method=1
        If method=1 Then method_name$="ellipsoid-to-ellipsoid"
        If method=2 Then method_name$="ellipsoid-to-polygon"
        If method=3 Then method_name$="ellipsoid-to-box"
    EndIf
    If KeyHit(19)
        response=response+1
        If response>3 Then response=1
        If response=1 Then response_name$="stop"
        If response=2 Then response_name$="slide"
        If response=3 Then response_name$="slide, but never down slopes"
    EndIf

    ; The star of the show: register collisions between the two types
    Collisions type_player,type_scenery,method,response

    ; UpdateWorld performs the collision checks and responses
    UpdateWorld

    RenderWorld

    Text 0,0,"Arrow keys: drive the ball   M: method   R: response   Esc: exit"
    Text 0,20,"Collisions type_player,type_scenery,"+method+","+response
    Text 0,40,"Method "+method+": "+method_name$+"   Response "+response+": "+response_name$
    Text 0,60,"Brush a crate corner with each method - sphere, exact mesh or box"

    Flip

Wend

End

Index