EntityBox entity,x#,y#,z#,width#,height#,depth#
Parameters
|
entity - entity handle x# - x coordinate of the box corner, relative to the entity's origin y# - y coordinate of the box corner, relative to the entity's origin z# - z coordinate of the box corner, relative to the entity's origin width# - width of the box (extent along x) height# - height of the box (extent along y) depth# - depth of the box (extent along z) |
Description
|
Sets an entity's collision box. The box is used when the entity is on the destination side of an ellipsoid-to-box collision pair (method 3 of the Collisions command) - a cheap fit for crates, platforms and doors without testing their actual polygons. x#,y#,z# place one corner of the box relative to the entity's origin and width#,height#,depth# extend it from there. To centre a 2x2x2 box on the origin: EntityBox crate,-1,-1,-1,2,2,2. The box follows the entity's position and rotation, but ignores ScaleEntity - if you scale the model up, set a bigger box to match. See also: EntityRadius, Collisions, EntityType. |
Example
; EntityBox 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 ; A crate with an adjustable collision box crate=CreateCube() PositionEntity crate,0,1,4 EntityColor crate,200,160,60 EntityType crate,type_scenery ; A translucent ghost cube visualises the collision box ghost=CreateCube() PositionEntity ghost,0,1,4 EntityColor ghost,80,200,255 EntityAlpha ghost,0.3 ; Ellipsoid-to-BOX collisions (method 3), so EntityBox is what the ball hits Collisions type_player,type_scenery,3,2 b#=1.8 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 ; [ and ] shrink or grow the collision box If KeyDown(26) And b>0.5 Then b=b-0.02 If KeyDown(27) And b<3 Then b=b+0.02 ; The star of the show: an axis-aligned collision box that can be ; bigger or smaller than the crate you actually see EntityBox crate,-b,-b,-b,b*2,b*2,b*2 ; Match the ghost cube to the box (a whisker larger to avoid flicker) ScaleEntity ghost,b*1.02,b*1.02,b*1.02 ; UpdateWorld performs the collision checks and the slide response UpdateWorld RenderWorld Text 0,0,"Arrow keys: drive the ball [ / ] : resize the box Esc: exit" Text 0,20,"EntityBox crate,"+(-b)+","+(-b)+","+(-b)+","+(b*2)+","+(b*2)+","+(b*2) Text 0,40,"The blue ghost is the collision box - the ball bounces off it, not the crate" Flip Wend End
Index