ApplyForce
Pushes a physics body during the next UpdateWorld.
ApplyForce entity,x#,y#,z#[,offset_x#][,offset_y#][,offset_z#]
Parameters
- entity
- entity handle
- x#, y#, z#
- the force, in world space
- offset_x#, offset_y#, offset_z# (optional)
- where to push, as an offset from the entity's position in world space. Defaults to the middle.
Description
Pushes a dynamic body during the next UpdateWorld. Call it every loop to keep pushing - for engines, wind or a hovering craft. A force of mass times gravity (9.8 by default) holds a body up against gravity.
It also blows soft bodies (EntitySoftBody) about, and pushes ragdolls (EntityRagdoll): all of it with an offset of 0,0,0, or the part nearest the offset point.
Pushing away from the middle makes the body turn as well. For a sudden push such as a jump or an explosion, use ApplyImpulse.
Example
; 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
