|
entity - enabled, enrolled free dynamic entity x# - force X in newtons y# - force Y in newtons z# - force Z in newtons global (optional) - True for world axes (default), False for entity axes |
|
Pushes a dynamic entity with a force for the next physics update. The force applies over the next positive UpdateWorld interval. Calls add together, and UpdateWorld 0 does not consume them. The engine applies the total over every native slice of that update, then clears it, so call it again each update for continuous thrust such as a rocket engine or a steady wind. Entity mass determines the acceleration. Local vectors use the entity rotation when issued, without scaling their magnitude. Static, kinematic, hidden/disabled and Collisions-controlled bodies reject this command; use authored movement for controlled players and kinematic platforms. ResetEntity and movement-role changes discard queued forces. The combined force and torque must have representable magnitudes; a rejected addition retains the previous queued input. Before a positive update starts, queued loads and gravity are checked against pending mass, inertia, motion, damping and the chosen substep. If these calculations are unrepresentable, the update reports an error before committing those edits or consuming the queue. Repair the settings or clear the loads with ResetEntity before retrying. Later slices check the motion produced so far; a failure after simulation has advanced is reported without claiming rollback of elapsed simulation. For the full story, see the entity-physics guide, or browse the compact command set. See also: EntityImpulse, EntityVelocity, EntityMass, EntityPhysics, UpdateWorld. |
; EntityForce 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
thrust#=15
timer=CreateTimer(60)
While Not KeyDown(1)
; Hold Space to fire a rocket engine under the crate; [ / ] change thrust
If KeyHit(26) And thrust>0 Then thrust=thrust-1
If KeyHit(27) And thrust<40 Then thrust=thrust+1
; A force lasts one update, so apply it every frame for continuous thrust
If KeyDown(57) Then EntityForce crate,0,thrust,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 Hold Space: thrust [ / ] : force R: drop again Esc: exit"
Text 0,20,"EntityForce crate,0,"+thrust+",0 (gravity pulls with about 9.81 on this 1 kg crate)"
Flip
WaitTimer timer
Wend
End