EntityType entity,collision_type[,recursive]

Parameters

entity - entity handle

collision_type - collision type number, in the range 0-999. 0 removes the entity from collision checking, and is what every new entity starts with

recursive (optional) - true to apply the collision type to the entity's children too; false (default)

Description

Sets the collision type of an entity - which collision rules apply to it.

Collision types are just numbers you invent to group your entities: say type 1 for the player, 2 for enemies, 3 for scenery. The Collisions command then declares which types collide with which, and UpdateWorld does the checking. An entity with type 0 (the default) takes no part in collisions at all.

Setting a type also resets the entity's collision state, exactly like ResetEntity: the entity is treated as freshly placed at its current position, so no collision fires against anything it has just moved through. Handy when teleporting; surprising if you change types mid-fall.

With recursive set to true the type is applied to the entity and every descendant - useful for making a whole loaded model hierarchy solid in one call.

See also: GetEntityType, Collisions, EntityRadius, EntityBox, ResetEntity.

Entity physics (Extended): the same type IDs select symmetric Physics pairs. A label does not enroll an entity; use EntityPhysics or an existing Collisions participation rule. Type 0 has no pair interactions, but an enrolled free dynamic body still receives gravity. Changing type refilters contacts and clears affected collision history while retaining its body, joints and dynamic velocity.

Example

; EntityType 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,0
EntityRadius player,1
; The star of the show: give the ball its collision type
EntityType player,type_player

; A wall whose collision type we will toggle, plus a crate that stays solid
wall=CreateCube()
ScaleEntity wall,7,1.5,0.5
PositionEntity wall,0,1.5,7
EntityColor wall,150,150,160
EntityType wall,type_scenery

crate=CreateCube()
ScaleEntity crate,1.2,1.2,1.2
PositionEntity crate,-4,1.2,3
EntityColor crate,200,160,60
EntityType crate,type_scenery

; Ellipsoid-to-polygon collisions with a sliding response
Collisions type_player,type_scenery,2,2

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

    ; Space toggles the wall's collision type between type_scenery and 0.
    ; Type 0 means the wall is ignored by all collision checking.
    If KeyHit(57)
        If GetEntityType(wall)=0
            EntityType wall,type_scenery
            EntityAlpha wall,1
        Else
            EntityType wall,0
            EntityAlpha wall,0.4
        EndIf
    EndIf

    ; UpdateWorld performs the collision checks and the slide response
    UpdateWorld

    RenderWorld

    Text 0,0,"Arrow keys: drive the ball   Space: toggle the wall's type   Esc: exit"
    Text 0,20,"EntityType wall,"+GetEntityType(wall)+"   (0 = no collision checking)"
    Text 0,40,"Set it to 0 and the ball drives straight through the ghost wall"

    Flip

Wend

End

Index