PhysicsBody

Links an entity to a body in the Physics' world: after each step its Transform is put where the body is, and turned as the body is. Make one with PhysicsBody.of, and add it as world.add(entity, PhysicsBody, PhysicsBody.of(box)).

A rigid body's place is its shapes' origin, the point (0, 0) they were made around, turned with the body: the point given to PhysicsWorld.rigidBody, which is its centre of mass unless its shapes are off centre, as a hammer's are. A soft body's place is the middle of its ring. A soft body has no one angle, so it turns as its first ring point goes round the middle, from where that was when the link was first followed. A particle does not turn. A body that has been removed leaves its entity where it was.

toString names the body, for example PhysicsBody(RigidBody(3)).

Samples

val world = PhysicsWorld()
val crate = world.rigidBody(Shape.box(20f, 20f), x = 0f, y = 0f)
val drop = world.particles.add(x = 0f, y = 0f)
// One link type for rigid bodies, soft bodies and particles.
assertPrints(PhysicsBody.of(crate), "PhysicsBody(RigidBody(0))")
assertPrints(PhysicsBody.of(drop), "PhysicsBody(Particle(0))")

Types

Link copied to clipboard

Makes the links, and is the component type they are stored under.

Functions

Link copied to clipboard
open override fun toString(): String