PhysicsShapeFriction shape,friction#
Parameters
|
shape - physics-shape handle returned by a shape command such as PhysicsBodyBox friction# - Coulomb friction coefficient, 0 or higher; usually between 0 and 1 |
Description
|
Sets how strongly material slot 1 grips touching shapes. Slot 1 is also the shape's base material. Use PhysicsShapeMaterialFriction to edit another slot and PhysicsShapeGetFriction to read it. Edits wake affected enabled bodies and invalidate cached material sampling without changing mass. Friction is what stops crates sliding down ramps and lets wheels bite. 0 is sheet ice, around 0.2 is polished floor, and values towards 1 grip like rubber. Every new shape starts at 0.6, a sensible general-purpose value. The friction actually felt at a contact combines the two touching shapes' values, so an icy floor makes everything slide regardless of what lands on it. Tune the pair, not just one side. Friction only fights sliding along surfaces - it does not slow bodies flying through the air. For that, see PhysicsBodyDamping. Requires Extended mode. See also: PhysicsShapeRestitution, PhysicsShapeFilter, PhysicsBodyDamping, PhysicsBodyBox. |
Example
; PhysicsShapeFriction Example ; ---------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,4,-6 RotateEntity camera,20,0,0 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 50,50,50 world=CreatePhysicsWorld() PhysicsGravity world,0,-9.81,0 ; A long static runway for the crate to slide along ground=CreateCube() ScaleEntity ground,8,0.5,2 PositionEntity ground,0,-0.5,5,True EntityColor ground,80,160,255 ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC) ground_shape=PhysicsBodyBox(ground_body,16,1,4,0) PhysicsShapeFriction ground_shape,1 ; The sliding crate whose friction we tune crate=CreateCube() ScaleEntity crate,0.4,0.4,0.4 PositionEntity crate,-5,0.4,5,True EntityColor crate,255,120,70 crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC) crate_shape=PhysicsBodyBox(crate_body,0.8,0.8,0.8,1) friction#=0.5 While Not KeyDown(1) ; [ and ] tune the crate's friction coefficient If KeyDown(26) And friction>0 Then friction=friction-0.01 If KeyDown(27) And friction<2 Then friction=friction+0.01 If friction<0 Then friction=0 ; Apply the current friction to the crate's shape PhysicsShapeFriction crate_shape,friction ; Space resets the crate and shoves it along the runway reset=0 If KeyHit(57) Then reset=1 If EntityY(crate,True)<-4 Then reset=1 If reset FreePhysicsBody crate_body PositionEntity crate,-5,0.4,5,True RotateEntity crate,0,0,0 crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC) crate_shape=PhysicsBodyBox(crate_body,0.8,0.8,0.8,1) PhysicsBodyImpulse crate_body,3,0,0 EndIf 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,"[ / ]: adjust friction Space: shove the crate Arrows: camera Esc: exit" Text 0,20,"PhysicsShapeFriction crate_shape,"+friction Text 0,40,"Slide distance: "+(EntityX(crate,True)+5)+" m (low friction slides further)" Flip Wend FreePhysicsWorld world End
Index