mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
add Rigidbody.is_enabled, .set_enabled
This commit is contained in:
parent
1ca0761f49
commit
6d7f950410
3 changed files with 32 additions and 7 deletions
|
|
@ -28,15 +28,19 @@ entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos) {
|
|||
auto id = nextID++;
|
||||
registry.emplace<EntityId>(entity, static_cast<entityid_t>(id));
|
||||
registry.emplace<Transform>(entity, pos, size/4.0f, glm::mat3(1.0f));
|
||||
registry.emplace<Hitbox>(entity, pos, def.hitbox);
|
||||
registry.emplace<Rigidbody>(entity, true, Hitbox {pos, def.hitbox});
|
||||
entities[id] = entity;
|
||||
return id;
|
||||
}
|
||||
|
||||
void Entities::updatePhysics(float delta){
|
||||
auto view = registry.view<Transform, Hitbox>();
|
||||
auto view = registry.view<Transform, Rigidbody>();
|
||||
auto physics = level->physics.get();
|
||||
for (auto [entity, transform, hitbox] : view.each()) {
|
||||
for (auto [entity, transform, rigidbody] : view.each()) {
|
||||
if (!rigidbody.enabled) {
|
||||
continue;
|
||||
}
|
||||
auto& hitbox = rigidbody.hitbox;
|
||||
physics->step(
|
||||
level->chunks.get(),
|
||||
&hitbox,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ struct Transform {
|
|||
void refresh();
|
||||
};
|
||||
|
||||
struct Rigidbody {
|
||||
bool enabled = true;
|
||||
Hitbox hitbox;
|
||||
};
|
||||
|
||||
class Level;
|
||||
class Assets;
|
||||
class LineBatch;
|
||||
|
|
@ -45,8 +50,8 @@ public:
|
|||
return registry.get<Transform>(entity);
|
||||
}
|
||||
|
||||
Hitbox& getHitbox() const {
|
||||
return registry.get<Hitbox>(entity);
|
||||
Rigidbody& getRigidbody() const {
|
||||
return registry.get<Rigidbody>(entity);
|
||||
}
|
||||
|
||||
entityid_t getUID() const {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue