ArcBasicDocs
3DPhysicsArcBasic extension

ApplyImpulse

Gives a physics body a sudden push.

ApplyImpulse entity,x#,y#,z#[,offset_x#][,offset_y#][,offset_z#]

Parameters

entity
entity handle
x#, y#, z#
the impulse, in world space
offset_x#, offset_y#, offset_z# (optional)
where to strike, as an offset from the entity's position in world space. Defaults to the middle.

Description

Gives a dynamic body a sudden push at once, changing its velocity by the impulse divided by its mass: jumps, kicks, hits and explosions.

On a soft body (EntitySoftBody) the impulse is shared by all its vertices. On a ragdoll (EntityRagdoll) an offset of 0,0,0 pushes the whole body; any other offset, from the entity's position, pushes the part nearest that point.

Striking away from the middle makes the body spin as well. To push steadily, use ApplyForce.

Example

ApplyImpulse.absOpen in editor
; Physics forces example (an ArcBasic extension); Arrows push the ball, Space makes it jump, T gives it a twistGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,10,-14TurnEntity camera,35,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,90,90,130EntityPhysics ground,1ball=CreateSphere(16)PositionEntity ball,0,1,0EntityColor ball,255,200,60EntityPhysics ball,2,1box=CreateCube()PositionEntity box,4,1,2EntityPhysics box,2,2While Not KeyHit(1)	; forces push steadily while the keys are held	If KeyDown(203) Then ApplyForce ball,-15,0,0	If KeyDown(205) Then ApplyForce ball,15,0,0	If KeyDown(200) Then ApplyForce ball,0,0,15	If KeyDown(208) Then ApplyForce ball,0,0,-15	; impulses act at once	If KeyHit(57) And EntityY(ball)<1.1 Then ApplyImpulse ball,0,6,0	If KeyHit(20) Then ApplyTorqueImpulse box,0,8,0 : ApplyImpulse box,0,10,0	If KeyHit(31) Then SetEntityVelocity ball,0,0,0 : SetEntitySpin ball,0,0,0	If KeyDown(25) Then ApplyTorque box,0,0,20	UpdateWorld	RenderWorld	Text 0,0,"Arrows: push   Space: jump   T: flip the box   P: roll the box   S: stop the ball"	speed#=Sqr(EntityVelocityX(ball)^2+EntityVelocityY(ball)^2+EntityVelocityZ(ball)^2)	Text 0,15,"Ball speed: "+speed+" units a second"	Text 0,30,"Box spin: "+EntitySpinPitch(box)+", "+EntitySpinYaw(box)+", "+EntitySpinRoll(box)	FlipWendEnd

See also