add entity event: on_fall

This commit is contained in:
MihailRis
2024-06-30 00:32:02 +03:00
parent 3946119a67
commit 50c714692a
5 changed files with 36 additions and 7 deletions
+6 -2
View File
@@ -67,6 +67,7 @@ void Entities::updatePhysics(float delta){
continue;
}
auto& hitbox = rigidbody.hitbox;
auto prevVel = hitbox.velocity;
bool grounded = hitbox.grounded;
physics->step(
level->chunks.get(),
@@ -77,11 +78,14 @@ void Entities::updatePhysics(float delta){
1.0f,
true
);
hitbox.linearDamping = hitbox.grounded * 12;
hitbox.linearDamping = hitbox.grounded * 24;
transform.pos = hitbox.position;
//transform.rot = glm::rotate(glm::mat4(transform.rot), delta, glm::vec3(0, 1, 0));
if (hitbox.grounded && !grounded) {
scripting::on_entity_grounded(eid.def, *get(eid.uid));
scripting::on_entity_grounded(*get(eid.uid), glm::length(prevVel-hitbox.velocity));
}
if (!hitbox.grounded && grounded) {
scripting::on_entity_fall(*get(eid.uid));
}
}
}