Body class

A rigid body. These are created via World.createBody.

Constructors

Body(BodyDef bd, World world)

Properties

angle double
Get the current world rotation angle in radians.
no setter
angularDamping double
getter/setter pair
angularVelocity double
Set the angular velocity.
getter/setter pair
bodyType BodyType
no setter
contacts List<Contact>
final
fixtures List<Fixture>
final
flags int
getter/setter pair
force Vector2
Do not modify directly
final
gravityOverride Vector2?
Changes how the World treats the gravity for this body.
getter/setter pair
gravityScale Vector2?
Multiplier for the body's gravity.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
inertia double
getter/setter pair
inverseInertia double
getter/setter pair
inverseMass double
no setter
isActive bool
Whether the body is active or not.
no setter
isAwake bool
Whether the body is awake or sleeping.
no setter
isBullet bool
Whether this body should be treated like a bullet for continuous collision detection.
getter/setter pair
islandIndex int
getter/setter pair
joints List<Joint>
final
linearDamping double
getter/setter pair
linearVelocity Vector2
The linear velocity of the center of mass. Do not modify directly, instead use applyLinearImpulse or applyForce.
finalgetter/setter pair
mass double
Get the total mass of the body, usually in kilograms (kg).
no setter
position Vector2
Get the world body origin position. Do not modify.
no setter
previousTransform Transform
The previous transform for particle simulation
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sleepTime double
getter/setter pair
sweep Sweep
The swept motion for CCD
final
torque double
no setter
transform Transform
The body origin transform.
final
userData Object?
Use this to store your application specific data.
getter/setter pair
world World
final
worldCenter Vector2
Get the world position of the center of mass. Do not modify.
no setter

Methods

advance(double t) → void
applyAngularImpulse(double impulse) → void
Apply an angular impulse.
applyForce(Vector2 force, {Vector2? point}) → void
Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.
applyLinearImpulse(Vector2 impulse, {Vector2? point, bool wake = true}) → void
Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body if 'wake' is set to true. If the body is sleeping and 'wake' is false, then there is no effect.
applyTorque(double torque) → void
Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.
clearForces() → void
Remove all the current forces on the body
createFixture(FixtureDef def) Fixture
Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.
createFixtureFromShape(Shape shape, {double density = 1.0, double friction = 0.0, double restitution = 0.0}) Fixture
Creates a fixture from a shape and attach it to this body. This is a convenience function. Use FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. If the density is non-zero, this function automatically updates the mass of the body.
destroyFixture(Fixture fixture) → void
Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed.
getInertia() double
Get the central rotational inertia of the body, usually in kg-m^2.
getLocalCenter() Vector2
Get the local position of the center of mass. Do not modify.
getMassData() MassData
Get the mass data of the body. The rotational inertia is relative to the center of mass.
isFixedRotation() bool
Does this body have fixed rotation?
isSleepingAllowed() bool
Whether this body allowed to sleep.
linearVelocityFromLocalPoint(Vector2 localPoint) Vector2
Get the world velocity of a local point.
linearVelocityFromWorldPoint(Vector2 worldPoint) Vector2
Get the world linear velocity of a world point attached to this body.
localPoint(Vector2 worldPoint) Vector2
Gets a local point relative to the body's origin given a world point.
localVector(Vector2 worldVector) Vector2
Gets a local vector given a world vector.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resetMassData() → void
This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called setMassData to override the mass and you later want to reset the mass.
setActive(bool flag) → void
Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a World object and remains in the body list.
setAwake(bool awaken) → void
Set the sleep state of the body. A sleeping body has very low CPU cost.
setFixedRotation(bool flag) → void
Set this body to have fixed rotation. This causes the mass to be reset.
setMassData(MassData massData) → void
Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.
setSleepingAllowed(bool flag) → void
You can disable sleeping on this body. If you disable sleeping, the body will be woken.
setTransform(Vector2 position, double angle) → void
Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior. Note: contacts are updated on the next call to World.step().
setType(BodyType type) → void
Set the type of this body. This may alter the mass and velocity.
shouldCollide(Body other) bool
This is used to prevent connected bodies from colliding. It may lie, depending on the collideConnected flag.
synchronizeFixtures() → void
synchronizeTransform() → void
toString() String
A string representation of this object.
override
worldPoint(Vector2 localPoint) Vector2
Get the world coordinates of a point given the local coordinates.
worldVector(Vector2 localVector) Vector2
Get the world coordinates of a vector given the local coordinates.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

activeFlag → const int
autoSleepFlag → const int
awakeFlag → const int
bulletFlag → const int
fixedRotationFlag → const int
islandFlag → const int
toiFlag → const int