| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <html>
- <head>
- <title>Blitz3D Docs</title>
- <link rel=stylesheet href=../css/commands.css type=text/css>
- </head>
- <body>
- <h1>Collisions src_type,dest_type,method,response</h1>
- <h1>Parameters</h1>
- <table>
- <tr>
- <td>
- src_type - entity type to be checked for collisions.
<br />
- dest_type - entity type to be collided with.
<br />
-
<br />
- method - collision detection method.
<br />
- 1: ellipsoid-to-ellipsoid collisions
<br />
- 2: ellipsoid-to-polygon collisions
<br />
- 3: ellipsoid-to-box collisions
<br />
-
<br />
- response - what the source entity does when a collision occurs.
<br />
- 1: stop
<br />
- 2: slide1 - full sliding collision
<br />
- 3: slide2 - prevent entities from sliding down slopes
- </td>
- </tr>
- </table>
- <h1>Description</h1>
- <table>
- <tr>
- <td>
- Enables collisions between two different entity types.
<br />
-
<br />
- Entity types are just numbers you assign to an entity using EntityType. Blitz then uses the entity types to check for collisions between all the entities that have those entity types.
<br />
-
<br />
- Blitz has many ways of checking for collisions, 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 EntityRadius.
<br />
-
<br />
- In the case of collision detection method 1 being selected (ellipsoid-to-ellipsoid), then the destination entities concerned will need to have an EntityRadius assigned to them too. In the case of method 3 being selected (ellipsoid-to-box), then the destination entities will need to have an EntityBox assigned to them. Method 2 (ellipsoid-to-polygon) requires nothing to be assigned to the destination entities.
<br />
-
<br />
- Not only does Blitz check for collisions, 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.
<br />
-
<br />
- All collision checking occurs, and collision responses are acted out, when UpdateWorld is called.
<br />
-
<br />
- 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 ClearCollisions command.
- <br>
- <br>
- See also: <a class=small href=EntityBox.htm>EntityBox</a>, <a class=small href=EntityRadius.htm>EntityRadius</a>, <a class=small href=Collisions.htm>Collisions</a>, <a class=small href=EntityType.htm>EntityType</a>, <a class=small href=ResetEntity.htm>ResetEntity</a>.
- </td>
- </tr>
- </table>
- <h1><a href=../3d_examples/Collisions.bb>Example</a></h1>
- <table>
- <tr>
- <td>
- ; Collisions Example
<br />
- ; ------------------
<br />
-
<br />
- Graphics3D 640,480
<br />
- SetBuffer BackBuffer()
<br />
-
<br />
- ; Set collision type values
<br />
- type_ground=1
<br />
- type_character=2
<br />
- type_scenery=3
<br />
-
<br />
- camera=CreateCamera()
<br />
- RotateEntity camera,45,0,0
<br />
- PositionEntity camera,0,15,-10
<br />
-
<br />
- light=CreateLight()
<br />
- RotateEntity light,45,0,0
<br />
-
<br />
- ; Create cube 'ground'
<br />
- cube=CreateCube()
<br />
- ScaleEntity cube,10,10,10
<br />
- EntityColor cube,0,127,0
<br />
- EntityType cube,type_ground
<br />
- PositionEntity cube,0,-5,0
<br />
-
<br />
- ; Create sphere 'character'
<br />
- sphere=CreateSphere( 32 )
<br />
- EntityColor sphere,127,0,0
<br />
- EntityRadius sphere,1
<br />
- EntityType sphere,type_character
<br />
- PositionEntity sphere,0,7,0
<br />
-
<br />
- ; Enable collisions between type_character and type_ground
<br />
- Collisions type_character,type_ground,2,2
<br />
-
<br />
- ; Create cylinder 'scenery'
<br />
- cylinder=CreateCylinder( 32 )
<br />
- ScaleEntity cylinder,2,2,2
<br />
- EntityColor cylinder,0,0,255
<br />
- EntityRadius cylinder,2
<br />
- EntityBox cylinder,-2,-2,-2,4,4,4
<br />
- EntityType cylinder,type_scenery
<br />
- PositionEntity cylinder,-4,7,-4
<br />
-
<br />
- ; Create cone 'scenery'
<br />
- cone=CreateCone( 32 )
<br />
- ScaleEntity cone,2,2,2
<br />
- EntityColor cone,0,0,255
<br />
- EntityRadius cone,2
<br />
- EntityBox cone,-2,-2,-2,4,4,4
<br />
- EntityType cone,type_scenery
<br />
- PositionEntity cone,4,7,-4
<br />
-
<br />
- ; Create prism 'scenery'
<br />
- prism=CreateCylinder( 3 )
<br />
- ScaleEntity prism,2,2,2
<br />
- EntityColor prism,0,0,255
<br />
- EntityRadius prism,2
<br />
- EntityBox prism,-2,-2,-2,4,4,4
<br />
- EntityType prism,type_scenery
<br />
- PositionEntity prism,-4,7,4
<br />
- RotateEntity prism,0,180,0
<br />
-
<br />
- ; Create pyramid 'scenery'
<br />
- pyramid=CreateCone( 4 )
<br />
- ScaleEntity pyramid,2,2,2
<br />
- EntityColor pyramid,0,0,255
<br />
- EntityRadius pyramid,2
<br />
- EntityBox pyramid,-2,-2,-2,4,4,4
<br />
- EntityType pyramid,type_scenery
<br />
- RotateEntity pyramid,0,45,0
<br />
- PositionEntity pyramid,4,7,4
<br />
-
<br />
- ; Set collision method and response values
<br />
- method=2
<br />
- response=2
<br />
-
<br />
- method_info$="ellipsoid-to-polygon"
<br />
- response_info$="slide1"
<br />
-
<br />
- While Not KeyDown( 1 )
<br />
-
<br />
- x#=0
<br />
- y#=0
<br />
- z#=0
<br />
-
<br />
- If KeyDown( 203 )=True Then x#=-0.1
<br />
- If KeyDown( 205 )=True Then x#=0.1
<br />
- If KeyDown( 208 )=True Then z#=-0.1
<br />
- If KeyDown( 200 )=True Then z#=0.1
<br />
-
<br />
- MoveEntity sphere,x#,y#,z#
<br />
- MoveEntity sphere,0,-0.02,0 ; gravity
<br />
-
<br />
- ; Change collision method
<br />
- If KeyHit( 50 )=True
<br />
- method=method+1
<br />
- If method=4 Then method=1
<br />
- If method=1 Then method_info$="ellipsoid-to-sphere"
<br />
- If method=2 Then method_info$="ellipsoid-to-polygon"
<br />
- If method=3 Then method_info$="ellipsoid-to-box"
<br />
- EndIf
<br />
-
<br />
- ; Change collision response
<br />
- If KeyHit( 19 )=True
<br />
- response=response+1
<br />
- If response=4 Then response=1
<br />
- If response=1 Then response_info$="stop"
<br />
- If response=2 Then response_info$="slide1"
<br />
- If response=3 Then response_info$="slide2"
<br />
- EndIf
<br />
-
<br />
- ; Enable collisions between type_character and type_scenery
<br />
- Collisions type_character,type_scenery,method,response
<br />
-
<br />
- ; Perform collision checking
<br />
- UpdateWorld
<br />
-
<br />
- RenderWorld
<br />
-
<br />
- Text 0,0,"Use cursor keys to move sphere"
<br />
- Text 0,20,"Press M to change collision Method (currently: "+method_info$+")"
<br />
- Text 0,40,"Press R to change collision Response (currently: "+response_info$+")"
<br />
- Text 0,60,"Collisions type_character,type_scenery,"+method+","+response
<br />
-
<br />
- Flip
<br />
-
<br />
- Wend
<br />
-
<br />
- End
- </td>
- </tr>
- </table>
- <br>
- <a target=_top href=../index.htm>Index</a><br>
- <br>
- Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Collisions&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
- </html>
|