mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
add mass, elasticity getters, setters to entity.rigidbody
This commit is contained in:
parent
1bba713502
commit
bd7f588800
4 changed files with 42 additions and 2 deletions
|
|
@ -316,9 +316,9 @@ void Entities::preparePhysics(float delta) {
|
|||
continue;
|
||||
}
|
||||
rigidbody.hitbox.mass = eid.def.bodyType == BodyType::DYNAMIC
|
||||
? eid.def.mass
|
||||
? rigidbody.mass
|
||||
: std::numeric_limits<float>::infinity();
|
||||
rigidbody.hitbox.elasticity = eid.def.elasticity;
|
||||
rigidbody.hitbox.elasticity = rigidbody.elasticity;
|
||||
hitboxes.emplace_back(&rigidbody.hitbox);
|
||||
if (!eid.def.solid) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ dv::value Rigidbody::serialize(bool saveVelocity, bool saveBodySettings) const {
|
|||
if (hitbox.crouching) {
|
||||
bodymap["crouch"] = hitbox.crouching;
|
||||
}
|
||||
bodymap["mass"] = mass;
|
||||
bodymap["elasticity"] = elasticity;
|
||||
}
|
||||
return bodymap;
|
||||
}
|
||||
|
|
@ -33,6 +35,8 @@ void Rigidbody::deserialize(const dv::value& root) {
|
|||
BodyTypeMeta.getItem(bodyTypeName, hitbox.type);
|
||||
root["crouch"].asBoolean(hitbox.crouching);
|
||||
root["damping"].asNumber(hitbox.linearDamping);
|
||||
root["mass"].asNumber(mass);
|
||||
root["elasticity"].asNumber(elasticity);
|
||||
}
|
||||
|
||||
template <void (*callback)(const Entity&, size_t, entityid_t)>
|
||||
|
|
@ -49,6 +53,8 @@ static sensorcallback create_sensor_callback(Entities& entities) {
|
|||
void Rigidbody::initialize(
|
||||
const EntityDef& def, entityid_t id, Entities& entities
|
||||
) {
|
||||
mass = def.mass;
|
||||
elasticity = def.elasticity;
|
||||
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
||||
for (auto& [i, box] : def.boxSensors) {
|
||||
SensorParams params {};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ struct Rigidbody {
|
|||
bool enabled = true;
|
||||
Hitbox hitbox;
|
||||
std::vector<Sensor> sensors;
|
||||
float mass;
|
||||
float elasticity;
|
||||
|
||||
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
||||
void deserialize(const dv::value& root);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue