Crates.io | shipyard_rapier2d |
lib.rs | shipyard_rapier2d |
version | 0.1.0 |
source | src |
created_at | 2021-02-04 21:32:35.198401 |
updated_at | 2021-03-21 19:19:18.287914 |
description | An integration with the physics engine rapier, for the shipard ECS. |
homepage | |
repository | https://github.com/lucaspoffo/shipyard_rapier |
max_upload_size | |
id | 350717 |
size | 28,921 |
Physics plugin with rapier for the shipyard ECS.
Based of bevy_rapier plugin.
Setup the physics in the shipyard world:
let world = World::new();
world.run(setup_physics).unwrap();
Create an body and a collider component, add those to an existent entity, or create a new one:
let body = RigidBodyBuilder::new_dynamic().translation(x, y);
let collider = ColliderBuilder::cuboid(rad, rad).density(1.0);
all_storages.add_entity((body, collider));
In your gameplay loop, execute the physics systems to simulate the world:
// Create rapier colliders, bodies and joints based on the shipyard components.
world.run(create_body_and_collider_system).unwrap();
world.run(create_joints_system).unwrap();
// Step the world based on a frame rate.
let frame_time = 60.0 / 1000.0; // 60 fps simulation
world.run_with_data(step_world_system, frame_time).unwrap();
// Remove any physics components from deleted entities.
world.run(destroy_body_and_collider_system).unwrap();