PhysicsBodyDamping body,linear#,angular#
Parameters
|
body - physics-body handle returned by CreatePhysicsBody linear# - drag applied to the body's movement, 0 or higher; 0 means none angular# - drag applied to the body's spin, 0 or higher; 0 means none |
Description
|
Sets a body's linear and angular damping. Damping bleeds speed off a body every step whether or not it touches anything - think air resistance. New bodies have none, so a sphere on smooth ground rolls practically forever and a spinning crate keeps spinning in mid-air. Small values (0.05 to 0.5) add a touch of drag that makes motion feel less like a vacuum; larger values feel like moving through water, and beyond that, honey. Angular damping is the usual fix for props that will not stop rolling or twirling. Damping scales with speed, so it gently settles slow objects without capping fast ones hard. Use it together with PhysicsShapeFriction, which only acts while surfaces are actually in contact. Requires Extended mode. See also: PhysicsBodyVelocity, PhysicsBodyAngularVelocity, PhysicsBodyGravityScale, PhysicsShapeFriction. |
Example
; PhysicsBodyDamping Example ; -------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,2,-7 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 50,50,50 ; Zero gravity so damping is the only thing slowing the crate world=CreatePhysicsWorld() PhysicsGravity world,0,0,0 ; Orange crate floating at the centre of the scene crate=CreateCube() ScaleEntity crate,0.75,0.75,0.75 PositionEntity crate,0,1.5,0,True EntityColor crate,255,120,70 crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC) crate_shape=PhysicsBodyBox(crate_body,1.5,1.5,1.5,1) ; Start with moderate damping and a healthy spin damping#=0.3 PhysicsBodyDamping crate_body,damping,damping PhysicsBodyAngularVelocity crate_body,1,4,0 While Not KeyDown(1) ; [ and ] change the damping value If KeyHit(26) And damping>0.05 Then damping=damping-0.1 If KeyHit(27) And damping<2 Then damping=damping+0.1 ; Apply the current damping to the body every frame PhysicsBodyDamping crate_body,damping,damping ; Space spins the crate up again so you can watch it decay If KeyHit(57) Then PhysicsBodyAngularVelocity crate_body,1,4,0 ; Advance the Box3D simulation by one 60 Hz step 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,"Space: spin crate [ / ]: damping Arrow keys: camera Esc: exit" Text 0,20,"PhysicsBodyDamping crate,"+damping+","+damping Text 0,40,"Spin speed Y: "+PhysicsBodyAngularVelocityY(crate_body)+" rad/s" Flip Wend FreePhysicsWorld world FreeEntity crate End
Index