| Crates.io | gravita-physics |
| lib.rs | gravita-physics |
| version | 0.1.0 |
| created_at | 2025-12-25 22:14:03.903082+00 |
| updated_at | 2025-12-25 22:14:03.903082+00 |
| description | A modular 2D physics engine for real-time games and simulations |
| homepage | |
| repository | https://github.com/cantoramann/gravita |
| max_upload_size | |
| id | 2005001 |
| size | 151,601 |
A modular 2D physics engine for real-time games and simulations.
PhysicsWorld
├── bodies: Vec<RigidBody>
├── integrator: Box<dyn Integrator>
├── collision_detector: Box<dyn CollisionDetector>
└── contacts: Vec<Contact>
use gravita_physics::{PhysicsWorld, RigidBody, CollisionShape, BodyType};
use gravita_math::{Vec2, Circle, AABB};
// Create world with gravity
let mut world = PhysicsWorld::new();
world.set_gravity(Vec2::new(0.0, -500.0));
// Add static ground
let ground = RigidBody::new(0, CollisionShape::AABB(
AABB::from_center_size(Vec2::ZERO, Vec2::new(800.0, 50.0))
))
.with_type(BodyType::Static)
.with_position(Vec2::new(400.0, 25.0));
world.add_body(ground);
// Add dynamic ball
let mut ball = RigidBody::new(0, CollisionShape::Circle(
Circle::new(Vec2::ZERO, 20.0)
))
.with_position(Vec2::new(400.0, 300.0))
.with_density(1.0);
ball.restitution = 0.8; // Bouncy!
world.add_body(ball);
// Game loop
loop {
world.step(1.0 / 60.0);
// Handle collisions
for event in world.get_collision_events() {
if event.impulse_magnitude > 100.0 {
// Play sound, deal damage, etc.
}
}
}
| Type | Moved by Physics | Moved by User | Use Case |
|---|---|---|---|
| Static | ❌ | ❌ | Ground, walls |
| Kinematic | ❌ | ✅ | Moving platforms |
| Dynamic | ✅ | ✅ | Players, projectiles |
MIT OR Apache-2.0