pub const RIGID_BODY: &str = "type RigidBody {\n kind: Str = \"dynamic\";\n mass: Number = 1;\n velocity: Vec3 = Vec3 {};\n angular_velocity: Vec3 = Vec3 {};\n restitution: Number = 0.3;\n friction: Number = 0.5;\n}";Expand description
Physical-body configuration for a Sphere or Box entity.
kind must be dynamic, fixed, or kinematic. Only dynamic bodies accept Force
or Impulse; fixed bodies must have zero velocities.
§Declaration
type RigidBody {
kind: Str = "dynamic";
mass: Number = 1;
velocity: Vec3 = Vec3 {};
angular_velocity: Vec3 = Vec3 {};
restitution: Number = 0.3;
friction: Number = 0.5;
}§Fields and methods
-
kind: dynamic, fixed, or kinematic; defaults to dynamic. -
mass: Positive mass used by the collider; defaults to 1. -
velocity: Linear velocity in meters per second; defaults to zero. -
angular_velocity: Angular velocity in radians per second; defaults to zero. -
restitution: Bounciness in 0..=1; defaults to 0.3. -
friction: Contact friction in 0..=1; defaults to 0.5.
§Advance a dynamic sphere
Systems run before physics in each fixed tick, so the second callback observes the position advanced by the first integration step.
let entity = spawn(Transform {});
add(entity, Sphere { radius: 0.5 });
add(entity, RigidBody { velocity: Vec3 { x: 1 } });
system Observe of Transform {
func frame(dt: Number) -> Unit {
if tick > 1 { print(self.position.x > 0); }
}
}§Choose a fixed body
Fixed bodies keep zero velocity.
let value = RigidBody { kind: "fixed" };
print(value.kind);