R3d.Body:setMass
Available since: Gideros 2020.2
Class: R3d.Body
Description
Sets the mass of the body.
r3d.Body:setMass(mass)
The mass, center of mass and inertia tensor of a rigid body are important parameters for the physical simulation of a rigid body.
Mass
The RigidBody has a mass value (in kilograms) which is 1 kilogram by default. There are two ways to set the mass of a rigid body. First, you can set it directly using the RigidBody::setMass() method. Secondly, it is also possible to compute this mass automatically using the mass of the colliders of the rigid body. The material of each collider has a mass density value. This value is 1 by default. You can change the mass density value of the colliders of a rigid body and then use the RigidBody::updateMassFromColliders() method to automatically compute the mass of the rigid body using the mass density and shape of its colliders. Note that you will need to call this method again if you add another collider to the rigid body.
Center of mass
The center of mass of a RigidBody is the mean location of the distribution of mass of the body in space. By default the center of mass of the rigid body is located at its origin. There are two ways to set the center of mass of a rigid body. First, you can set it directly using the RigidBody::setLocalCenterOfMass() method. Secondly, as for the mass, the center of mass can also be computed automatically using the mass, shape and transform of all the colliders of the rigid body. The material of each collider has a mass density value. This value is 1 by default. You can set the mass density value of the colliders and then use the RigidBody::updateLocalCenterOfMassFromColliders() method to automatically compute the center of mass of the rigid body. Note that you will need to call this method again if you add another collider to the rigid body.
Inertia Tensor
The inertia tensor of a RigidBody is a matrix describing how the mass is distributed inside the rigid body which is used to calculate its rotation. The inertia tensor depends on the mass and the shape of the body. By default the local inertia tensor of a rigid body is the identity matrix. There are two ways to set the inertia tensor of a rigid body. First, you can set it directly using the RigidBody::setLocalInertiaTensor() method. Note that this will set the inertia tensor of the body in local-space coordinates which is usually a diagonal matrix. This method takes a Vector3 with the three diagonal entries of the matrix. Secondly, the local inertia tensor can be computed automatically using the mass density, shape and transform of all the colliders of the body. The material of each collider has a mass density value which is 1 by default. You can set the mass density value of the colliders and then use the RigidBody::updateLocalInertiaTensorFromColliders() method to automatically compute the local inertia tensor of the body. Note that you will need to call this method again if you add another collider to the rigid body.
Note that it is also possible to automatically compute the mass, center of mass and inertia tensor of a rigid body at the same time using RigidBody::updateMassPropertiesFromColliders().
Parameters
mass: (number) the new body mass
Example
player1.body:setMass(2)
- R3d.Body
- R3d.Body.DYNAMIC BODY
- R3d.Body.KINEMATIC BODY
- R3d.Body.STATIC BODY
- R3d.Body:applyLocalForceAtCenterOfMass
- R3d.Body:applyLocalForceAtLocalPosition
- R3d.Body:applyLocalForceAtWorldPosition
- R3d.Body:applyLocalTorque
- R3d.Body:applyWorldForceAtCenterOfMass
- R3d.Body:applyWorldForceAtLocalPosition
- R3d.Body:applyWorldForceAtWorldPosition
- R3d.Body:applyWorldTorque
- R3d.Body:createFixture
- R3d.Body:destroyFixture
- R3d.Body:enableGravity
- R3d.Body:getAngularDamping
- R3d.Body:getAngularLockAxisFactor
- R3d.Body:getAngularVelocity
- R3d.Body:getForce
- R3d.Body:getLinearDamping
- R3d.Body:getLinearLockAxisFactor
- R3d.Body:getLinearVelocity
- R3d.Body:getMass
- R3d.Body:getTorque
- R3d.Body:getTransform
- R3d.Body:raycast
- R3d.Body:resetForce
- R3d.Body:resetTorque
- R3d.Body:setAngularDamping
- R3d.Body:setAngularLockAxisFactor
- R3d.Body:setAngularVelocity
- R3d.Body:setIsActive
- R3d.Body:setIsAllowedToSleep
- R3d.Body:setIsSleeping
- R3d.Body:setLinearDamping
- R3d.Body:setLinearLockAxisFactor
- R3d.Body:setLinearVelocity
- R3d.Body:setMass
- R3d.Body:setSprite
- R3d.Body:setTransform
- R3d.Body:setType
- R3d.Body:testPointInside
- R3d.Body:updateMassPropertiesFromColliders