ArcBasicDocs
3DPhysicsArcBasic extension

EntityPhysics

Gives an entity a physics body: 0 none, 1 static, 2 dynamic, 3 kinematic, 4 trigger.

EntityPhysics entity[,mode][,mass#]

Parameters

entity
entity handle
mode (optional)
0: no physics, 1: static, 2: dynamic (default), 3: kinematic, 4: trigger
mass# (optional)
mass of a dynamic body. Defaults to 1.

Description

Gives an entity a physics body, so that UpdateWorld moves it as a real object would: it falls, slides, tumbles, bounces and pushes other bodies around.

Static bodies never move: use them for the ground, walls and scenery. Dynamic bodies are moved by the simulation: crates, balls, debris. Kinematic bodies are moved by your program (with PositionEntity, MoveEntity, TurnEntity and so on) and push dynamic bodies out of their way: lifts, doors, moving platforms and player characters.

The body's shape is worked out from the entity's mesh unless you choose one with EntityShape: dynamic bodies get a hull (the mesh shrink-wrapped), while static and kinematic bodies collide with the mesh's own triangles, so terrains and level meshes work as they are. A plane is endless flat ground; a pivot is a sphere of its EntityRadius. Child entities' meshes are part of the shape, unless the child has a body of its own.

You can still move a dynamic body yourself: PositionEntity or RotateEntity puts it in its new place at the next UpdateWorld, keeping its velocity. Hidden entities take no part until shown again, and copies made with CopyEntity get a body of their own. Mode 0 removes the body.

A trigger (4) is not a body: nothing collides with it, but it notices the bodies inside it - for finish lines, pickups, traps and doors that open as you come near. See TriggerCount. To make one invisible, use a pivot with a size given by EntityShape, or EntityAlpha 0; a hidden trigger is switched off.

Physics works alongside the classic Collisions: an entity with a dynamic body can still be hit by entities moved with collisions, but it is moved only by physics.

Example

EntityPhysics.absOpen in editor
; Physics example (an ArcBasic extension); Bodies fall, tumble and come to rest. Space drops another, G changes gravityGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,6,-16TurnEntity camera,15,0,0light=CreateLight()RotateEntity light,50,30,0; static bodies never moveground=CreatePlane()EntityColor ground,80,140,80EntityPhysics ground,1ramp=CreateCube()ScaleEntity ramp,4,.2,3RotateEntity ramp,0,0,25PositionEntity ramp,-3,2,0EntityPhysics ramp,1EntityFriction ramp,.2PhysicsRate 60moon=FalseWhile Not KeyHit(1)	If KeyHit(57)		; dynamic bodies are moved by the simulation		If Rand(0,1)			body=CreateCube()			ScaleEntity body,.5,.5,.5			EntityPhysics body,2,2		Else			body=CreateSphere(12)			ScaleEntity body,.4,.4,.4			EntityPhysics body,2,1			EntityBounce body,.6			EntityDamping body,.05,.5		EndIf		PositionEntity body,Rnd(-5,-2),8,Rnd(-1,1)		TurnEntity body,Rnd(360),Rnd(360),0		EntityColor body,Rand(100,255),Rand(100,255),Rand(100,255)		EntityMass body,1	EndIf	If KeyHit(34)		moon=Not moon		If moon Then PhysicsGravity 0,-1.6,0 Else PhysicsGravity 0,-9.8,0	EndIf	UpdateWorld	RenderWorld	Text 0,0,"Space: drop a body   G: change gravity"	If body Then Text 0,15,"Last body's physics mode: "+GetEntityPhysics(body)	FlipWendEnd

See also