PhysicsBodyImpulseAt body,impulse_x#,impulse_y#,impulse_z#,x#,y#,z#
Parameters
|
body - live explicit physics body handle impulse_x# - world-space vector component impulse_y# - world-space vector component impulse_z# - world-space vector component x# - world-space coordinate or vector component; see units below y# - world-space coordinate or vector component; see units below z# - world-space coordinate or vector component; see units below |
Description
|
Applies a world-space impulse in newton-seconds at a world-space point in metres. An off-centre application also produces angular motion. Apply once for an instantaneous change of momentum. Wakes the dynamic body and its connected island. Static, kinematic and disabled bodies do not respond. Every component must be finite. Ordinary accessors and setters reject stale or wrong-kind handles. Physics objects are owned by their world; deleting a body, entity tree or world also invalidates its dependent handles. Requires Extended mode. See also: CreatePhysicsBody, StepPhysics. |
Example
; PhysicsBodyImpulseAt Example ; ---------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,3,-7 RotateEntity camera,20,0,0 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 60,60,60 ; An independent Box3D world with standard gravity world=CreatePhysicsWorld() ; Blue static floor ground=CreateCube() ScaleEntity ground,6,0.5,6 PositionEntity ground,0,-0.5,0 EntityColor ground,80,160,255 ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC) ground_shape=PhysicsBodyBox(ground_body,12,1,12) ; An orange plank to push around plank=CreateCube() ScaleEntity plank,1.5,0.25,0.5 EntityColor plank,255,120,70 plank_body=CreatePhysicsBody(world,plank,PHYSICS_DYNAMIC) plank_shape=PhysicsBodyBox(plank_body,3,0.5,1) ResetPhysicsBody plank_body,0,1,0,0,0,0 While Not KeyDown(1) ; R puts the plank back in the middle If KeyHit(19) Then ResetPhysicsBody plank_body,0,1,0,0,0,0 ; The plank's right-hand end in world space TFormPoint 1,0,0,plank,0 ; Space kicks that end upwards once If KeyHit(57) Then PhysicsBodyImpulseAt plank_body,0,5,0,TFormedX(),TFormedY(),TFormedZ() StepPhysics world,1.0/60.0,4 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera R: reset Space: kick one end Esc: exit" Text 0,20,"PhysicsBodyImpulseAt plank_body,0,5,0 at the right-hand end" Text 0,40,"An impulse away from the centre of mass flips the plank over" Flip Wend FreePhysicsWorld world End
Index