add rigidbody.set/get_gravity_scale
This commit is contained in:
parent
cb37d3b00c
commit
b4cf00a8f1
@ -144,6 +144,20 @@ static int l_rigidbody_set_size(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_rigidbody_get_gravity_scale(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
return lua::pushnumber(L, entity->getRigidbody().hitbox.gravityScale);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_rigidbody_set_gravity_scale(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
entity->getRigidbody().hitbox.gravityScale = lua::tonumber(L, 2);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int index_range_check(const rigging::Rig& rig, lua::Integer index) {
|
static int index_range_check(const rigging::Rig& rig, lua::Integer index) {
|
||||||
if (static_cast<size_t>(index) >= rig.pose.matrices.size()) {
|
if (static_cast<size_t>(index) >= rig.pose.matrices.size()) {
|
||||||
throw std::runtime_error("index out of range [0, " +
|
throw std::runtime_error("index out of range [0, " +
|
||||||
@ -222,5 +236,7 @@ const luaL_Reg rigidbodylib [] = {
|
|||||||
{"set_vel", lua::wrap<l_rigidbody_set_vel>},
|
{"set_vel", lua::wrap<l_rigidbody_set_vel>},
|
||||||
{"get_size", lua::wrap<l_rigidbody_get_size>},
|
{"get_size", lua::wrap<l_rigidbody_get_size>},
|
||||||
{"set_size", lua::wrap<l_rigidbody_set_size>},
|
{"set_size", lua::wrap<l_rigidbody_set_size>},
|
||||||
|
{"get_gravity_scale", lua::wrap<l_rigidbody_get_gravity_scale>},
|
||||||
|
{"set_gravity_scale", lua::wrap<l_rigidbody_set_gravity_scale>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -97,7 +97,7 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||||||
|
|
||||||
hitbox->linearDamping = PLAYER_GROUND_DAMPING;
|
hitbox->linearDamping = PLAYER_GROUND_DAMPING;
|
||||||
hitbox->verticalDamping = flight;
|
hitbox->verticalDamping = flight;
|
||||||
hitbox->gravityMultiplier = flight ? 0.0f : 1.0f;
|
hitbox->gravityScale = flight ? 0.0f : 1.0f;
|
||||||
if (flight){
|
if (flight){
|
||||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||||
if (input.jump){
|
if (input.jump){
|
||||||
|
|||||||
@ -43,7 +43,7 @@ struct Hitbox {
|
|||||||
float linearDamping;
|
float linearDamping;
|
||||||
bool verticalDamping = false;
|
bool verticalDamping = false;
|
||||||
bool grounded = false;
|
bool grounded = false;
|
||||||
float gravityMultiplier = 1.0f;
|
float gravityScale = 1.0f;
|
||||||
|
|
||||||
Hitbox(glm::vec3 position, glm::vec3 halfsize);
|
Hitbox(glm::vec3 position, glm::vec3 halfsize);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -32,7 +32,7 @@ void PhysicsSolver::step(
|
|||||||
const glm::vec3& half = hitbox->halfsize;
|
const glm::vec3& half = hitbox->halfsize;
|
||||||
glm::vec3& pos = hitbox->position;
|
glm::vec3& pos = hitbox->position;
|
||||||
glm::vec3& vel = hitbox->velocity;
|
glm::vec3& vel = hitbox->velocity;
|
||||||
float gravityScale = hitbox->gravityMultiplier;
|
float gravityScale = hitbox->gravityScale;
|
||||||
|
|
||||||
bool prevGrounded = hitbox->grounded;
|
bool prevGrounded = hitbox->grounded;
|
||||||
hitbox->grounded = false;
|
hitbox->grounded = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user