EntityImpulse entity,x#,y#,z#[,global]

Parameters

entity - enabled, enrolled free dynamic entity

x# - impulse X in kilogram metres per second
y# - impulse Y in kilogram metres per second
z# - impulse Z in kilogram metres per second

global (optional) - True for world axes (default), False for entity axes

Description

Gives a dynamic entity an instant kick of momentum.

Use it for jumps, explosions and bat-and-ball hits. The velocity change is the impulse divided by mass, and the impulse is not repeated for each solver slice. Local vectors are rotated when issued, without scale.

A free dynamic body is required; static, kinematic, hidden/disabled and Collisions-controlled bodies reject it. A later EntityVelocity assignment replaces the velocity produced by earlier impulses. Use EntityForce for sustained acceleration. Inputs that overflow the mass-scaled velocity or squared-speed calculation are rejected before applying the impulse.

For the full story, see the entity-physics guide, or browse the compact command set.


See also: EntityForce, EntityVelocity, EntityMass, EntityPhysics.

Example

; EntityImpulse Example
; ---------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; Entity physics runs on the Box3D collision backend
SetCollisionBackend 1

Const SCENERY=1
Const PROPS=2

camera=CreateCamera()
PositionEntity camera,0,3,-10
RotateEntity camera,10,0,0

light=CreateLight()
RotateEntity light,45,-25,0
AmbientLight 80,80,90

; A static floor for the crate to land on
ground=CreateCube()
ScaleEntity ground,10,0.5,10
PositionEntity ground,0,-0.5,0
EntityColor ground,65,85,100
EntityType ground,SCENERY
EntityPhysics ground,0

; A dynamic crate that falls and settles on its own
crate=CreateCube()
ScaleEntity crate,0.5,0.5,0.5
PositionEntity crate,0,4,0
RotateEntity crate,0,0,0
EntityColor crate,235,155,65
EntityType crate,PROPS
EntityPhysics crate

; Props collide physically with the scenery
Physics PROPS,SCENERY

strength#=5

timer=CreateTimer(60)

While Not KeyDown(1)

    ; Space kicks the crate upwards; [ / ] change the kick
    If KeyHit(26) And strength>1 Then strength=strength-1
    If KeyHit(27) And strength<15 Then strength=strength+1
    If KeyHit(57) Then EntityImpulse crate,0,strength,0

    ; R drops the crate again
    If KeyHit(19)
        PositionEntity crate,0,4,0
        RotateEntity crate,0,0,0
        ResetEntity crate
    EndIf

    ; 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

    UpdateWorld
    RenderWorld

    Text 0,0,"Arrow keys: move camera   Space: kick   [ / ] : strength   R: drop again   Esc: exit"
    Text 0,20,"EntityImpulse crate,0,"+strength+",0   (an instant change of momentum)"

    Flip
    WaitTimer timer

Wend

End

Index