Setting the gravityEdit

The gravity force isn't a property of each body, it's global, so you can set it using CraftStudio.Physics.SetGravity


Physics:SetBodyType( [Physics.BodyType] body type )

Sets up the body's type. Possible values:

  • Physics.BodyType.Dynamic - Dynamic bodies are affected by forces (including gravity) and can be moved around
  • Physics.BodyType.Static - Static bodies can't be moved and aren't affected by gravity, useful for scenery
  • Physics.BodyType.Kinematic - Kinematic bodies can be moved programmatically but aren't affected by forces (useful for moving obstacles)

Physics:SetupAsBox, Physics:SetupAsSphere, Physics:SetupAsCapsule, Physics:SetupAsMapEdit

Physics:SetupAsBox( [Vector3] size )
Physics:SetupAsSphere( [number] radius )
Physics:SetupAsCapsule( [number] radius, [number] height )
Physics:SetupAsMap( [Map] map, [TileSet] tileSet=nil )

Sets up the body's shape.


Physics:SetMass( [number] mass )

Sets the body's mass.

Only makes sense on Dynamic bodies.

Physics:ApplyForce, Physics:ApplyImpulseEdit

Physics:ApplyForce( [Vector3] force, [Vector3] relative position=nil )
Physics:ApplyImpulse( [Vector3] impulse, [Vector3] relative position=nil )

Applies the specified force or impulse on the body. If relative position is nil, then a central force / impulse is applied by default.

A force modifies the body's acceleration (which in turns affects the object's velocity over time).

An impulse modifies the body's velocity directly.

Only works on Dynamic bodies.

Physics:ApplyTorque, Physics:ApplyTorqueImpulseEdit

Physics:ApplyTorque( [Vector3] torque )
Physics:ApplyTorqueImpulse( [Vector3] impulse )

Applies the specified torque or torque impulse on the body. If relative position is nil, then a central force / impulse is applied by default.

A torque modifies the body's angular acceleration (which in turns affects the object's angular velocity over time).

An impulse modifies the body's angular velocity directly.

Only works on Dynamic bodies.

Physics:WarpPosition, Physics:OffsetPositionEdit

Physics:WarpPosition( [Vector3] position )
Physics:OffsetPosition( [Vector3] offset )

Teleports or offsets the body to/by the specified position/offset. Especially useful for moving around kinematic bodies (moving platforms in a platformer, opening doors & so on)

Works on Dynamic and Kinematic bodies.

(Physics:WarpPosition was previously called Physics:Teleport but has been renamed for consistency)

Physics:WarpEulerAngles / Physics:WarpOrientation / Physics:OffsetEulerAngles / Physics:OffsetOrientationEdit

Physics:WarpEulerAngles( [Vector3] euler Angles )
Physics:WarpOrientation( [Quaternion] orientation )

Physics:OffsetEulerAngles( [Vector3] euler Angles offset )
Physics:OffsetOrientation( [Quaternion] orientation offset )

WarpEulerAngles / WarpOrientation sets the object's orientation.

OffsetEulerAngles / OffsetOrientation applies the specified Euler angles / orientation as an offset to its current orientation.

Works on Dynamic and Kinematic bodies.

Physics:GetLinearVelocity, Physics:SetLinearVelocityEdit

[Vector3] Physics:GetLinearVelocity()
Physics:SetLinearVelocity( [Vector3] velocity )

Returns or sets the body's linear velocity.

Only makes sense on Dynamic bodies.

Physics:GetAngularVelocity, Physics:SetAngularVelocityEdit

[Vector3] Physics:GetAngularVelocity()
Physics:SetAngularVelocity( [Vector3] velocity )

Returns or sets the body's angular velocity.

Only makes sense on Dynamic bodies.

Physics:SetFreezePosition, Physics:SetFreezeRotationEdit

Physics:SetFreezePosition( [boolean] x, [boolean] y, [boolean] z )
Physics:SetFreezeRotation( [boolean] x, [boolean] y, [boolean] z )

Sets whether object's position / orientation is fixed around each axis.

Only makes sense on Dynamic bodies.

Example: Freezing an object's rotation entirelyEdit

​self.gameObject.physics:SetFreezeRotation( true, true, true )

Physics:GetFriction, Physics:SetFrictionEdit

[number] Physics:GetFriction()
Physics:SetFriction( [number] factor )

Returns or sets the body's friction as a number, 0 being no friction (very slippery) and 1 being high friction (very sticky). Default friction value for newly-created bodies is 1.

Physics:GetAnisotropicFriction, Physics:SetAnisotropicFrictionEdit

[Vector3] Physics:GetAnisotropicFriction()
Physics:SetAnisotropicFriction( [Vector3] friction )

Returns or sets the body's anisotropic friction.

Anisotropic basically means "not the same on all axes". By default, anisotropic friction is disabled (friction is the same on all axes).

Example: No vertical frictionEdit

-- Sets the overall friction coefficient
self.gameObject.physics:SetFriction( 0.5 )

-- Disable friction on the Y axis (vertically)
self.gameObject.physics:SetAnisotropicFriction( Vector3:New( 1, 0, 1 ) )