EntityShape
Sets the shape of a physics body: 0 auto, 1 box, 2 sphere, 3 capsule, 4 cylinder, 5 hull, 6 mesh.
Parameters
- entity
- entity handle
- shape
- 0: automatic, 1: box, 2: sphere, 3: capsule, 4: cylinder, 5: hull, 6: mesh
- x#, y#, z# (optional)
- size of the shape; see below. Leave them out to fit the shape around the entity's mesh.
- offset_x#, offset_y#, offset_z# (optional)
- where the shape sits, relative to the entity, in the entity's own units
- pitch#, yaw#, roll# (optional)
- how the shape is turned, relative to the entity
Description
Chooses the shape of an entity's physics body. Call EntityPhysics first.
Box: x#, y# and z# are its width, height and depth. Sphere: x# is its radius. Capsule and cylinder: x# is the radius and y# the height, standing upright along the entity's Y axis. Sizes are in the entity's own units, so ScaleEntity scales the shape too. Without sizes the shape is fitted around the mesh (and its children's meshes).
A hull is the mesh shrink-wrapped: right for most dynamic objects. A mesh shape collides with every triangle and can only be used by static and kinematic bodies. Simple shapes are the fastest, and spheres, capsules and cylinders roll properly where a hull of a round mesh would be slightly bumpy.
Automatic (0) picks a hull for dynamic bodies and a mesh for static and kinematic ones. A mesh shape is hollow: a body or test entirely inside it, touching none of its triangles, does not meet it. Give closed static objects such as boxes and pillars a simple shape or a hull if things may end up inside them, or are moving fast enough to pass through their surface in one step.
EntityShape replaces all the body's shapes with one. To build a body from several shapes, such as a table from a top and four legs, add more with AddEntityShape.
Example
; Physics shapes example (an ArcBasic extension); A table made of five boxes, and a ball that rolls under it. D shows the shapesGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,4,-9TurnEntity camera,20,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,80,120,80EntityPhysics ground,1; the table is a pivot with a top and four legs as children, for looks...table=CreatePivot()top=CreateCube(table) : ScaleEntity top,2,.1,1 : PositionEntity top,0,2,0For x=-1 To 1 Step 2 For z=-1 To 1 Step 2 leg=CreateCube(table) : ScaleEntity leg,.1,1,.1 : PositionEntity leg,x*1.8,1,z*.8 NextNextEntityColor top,160,110,60PositionEntity table,0,3,0TurnEntity table,0,20,8; ...and one body built from five boxes, so there is room underneathEntityPhysics table,2,5EntityShape table,1,4,.2,2,0,2,0For x=-1 To 1 Step 2 For z=-1 To 1 Step 2 AddEntityShape table,1,.2,2,.2,x*1.8,1,z*.8 NextNextball=CreateSphere(12)ScaleEntity ball,.4,.4,.4PositionEntity ball,-6,.4,0EntityColor ball,250,200,60EntityPhysics ball,2debug=FalseWhile Not KeyHit(1) If KeyHit(57) Then SetEntityVelocity ball,6,0,0 If KeyHit(32) debug=Not debug PhysicsDebug debug EndIf UpdateWorld RenderWorld Text 0,0,"Space: roll the ball D: show the physics shapes" FlipWendEnd
