flutter_scene_box3d 0.2.2 copy "flutter_scene_box3d: ^0.2.2" to clipboard
flutter_scene_box3d: ^0.2.2 copied to clipboard

box3d physics backend for flutter_scene. Implements the physics simulation contract from package:scene against the box3d engine.

example/example.dart

// Drop a box onto a floor with the box3d backend.
import 'package:flutter_scene/physics.dart';
import 'package:flutter_scene/scene.dart';
import 'package:flutter_scene_box3d/flutter_scene_box3d.dart';
import 'package:vector_math/vector_math.dart';

Future<void> main() async {
  await Box3dPhysicsWorld.ensureInitialized();

  final scene = Scene();
  final world = PhysicsWorld(Box3dPhysicsWorld(gravity: Vector3(0, -9.81, 0)));
  scene.root.addComponent(world);

  // A static floor.
  final floor = Node(localTransform: Matrix4.translation(Vector3(0, -0.5, 0)));
  floor.addComponent(RigidBody(type: BodyType.fixed));
  floor.addComponent(
    Collider(shape: BoxShape(halfExtents: Vector3(10, 0.5, 10))),
  );
  scene.add(floor);

  // A falling dynamic box. The body goes on before the collider.
  final box = Node(localTransform: Matrix4.translation(Vector3(0, 5, 0)));
  box.addComponent(RigidBody(type: BodyType.dynamic_));
  box.addComponent(Collider(shape: BoxShape(halfExtents: Vector3.all(0.5))));
  scene.add(box);

  world.collisions.listen((event) {
    // CollisionBegan, CollisionEnded, TriggerEntered, or TriggerExited.
  });

  // Each frame, scene.update(deltaSeconds) steps physics on a fixed
  // timestep and interpolates node transforms before rendering.
}
2
likes
160
points
375
downloads

Documentation

API reference

Publisher

verified publisherbdero.dev

Weekly Downloads

box3d physics backend for flutter_scene. Implements the physics simulation contract from package:scene against the box3d engine.

Repository (GitHub)
View/report issues

Topics

#physics #box3d #gamedev #collision

License

MIT (license)

Dependencies

box3d, scene, vector_math

More

Packages that depend on flutter_scene_box3d