update vertical damping & add rigidbody:get_vdamping
This commit is contained in:
parent
67a5741ed2
commit
e064ace885
@ -95,10 +95,12 @@ body:get_linear_damping() -> number
|
|||||||
-- Sets the linear velocity attenuation multiplier
|
-- Sets the linear velocity attenuation multiplier
|
||||||
body:set_linear_damping(value: number)
|
body:set_linear_damping(value: number)
|
||||||
|
|
||||||
-- Checks if vertical velocity attenuation is enabled
|
-- Checks if vertical damping is enabled
|
||||||
body:is_vdamping() -> bool
|
body:is_vdamping() -> bool
|
||||||
-- Enables/disables vertical velocity attenuation
|
-- Returns the vertical damping multiplier
|
||||||
body:set_vdamping(enabled: bool)
|
body:get_vdamping() -> number
|
||||||
|
-- Enables/disables vertical damping / sets vertical damping multiplier
|
||||||
|
body:set_vdamping(enabled: bool | number)
|
||||||
|
|
||||||
-- Checks if the entity is on the ground
|
-- Checks if the entity is on the ground
|
||||||
body:is_grounded() -> bool
|
body:is_grounded() -> bool
|
||||||
|
|||||||
@ -97,8 +97,10 @@ body:set_linear_damping(value: number)
|
|||||||
|
|
||||||
-- Проверяет, включено ли вертикальное затухание скорости
|
-- Проверяет, включено ли вертикальное затухание скорости
|
||||||
body:is_vdamping() -> bool
|
body:is_vdamping() -> bool
|
||||||
-- Включает/выключает вертикальное затухание скорости
|
-- Возвращает множитель вертикального затухания скорости
|
||||||
body:set_vdamping(enabled: bool)
|
body:get_vdamping() -> number
|
||||||
|
-- Включает/выключает вертикальное затухание скорости / устанавливает значение множителя
|
||||||
|
body:set_vdamping(enabled: bool | number)
|
||||||
|
|
||||||
-- Проверяет, находится ли сущность на земле (приземлена)
|
-- Проверяет, находится ли сущность на земле (приземлена)
|
||||||
body:is_grounded() -> bool
|
body:is_grounded() -> bool
|
||||||
|
|||||||
@ -25,6 +25,7 @@ local Rigidbody = {__index={
|
|||||||
get_linear_damping=function(self) return __rigidbody.get_linear_damping(self.eid) end,
|
get_linear_damping=function(self) return __rigidbody.get_linear_damping(self.eid) end,
|
||||||
set_linear_damping=function(self, f) return __rigidbody.set_linear_damping(self.eid, f) end,
|
set_linear_damping=function(self, f) return __rigidbody.set_linear_damping(self.eid, f) end,
|
||||||
is_vdamping=function(self) return __rigidbody.is_vdamping(self.eid) end,
|
is_vdamping=function(self) return __rigidbody.is_vdamping(self.eid) end,
|
||||||
|
get_vdamping=function(self) return __rigidbody.get_vdamping(self.eid) end,
|
||||||
set_vdamping=function(self, b) return __rigidbody.set_vdamping(self.eid, b) end,
|
set_vdamping=function(self, b) return __rigidbody.set_vdamping(self.eid, b) end,
|
||||||
is_grounded=function(self) return __rigidbody.is_grounded(self.eid) end,
|
is_grounded=function(self) return __rigidbody.is_grounded(self.eid) end,
|
||||||
is_crouching=function(self) return __rigidbody.is_crouching(self.eid) end,
|
is_crouching=function(self) return __rigidbody.is_crouching(self.eid) end,
|
||||||
|
|||||||
@ -62,6 +62,15 @@ static int l_set_gravity_scale(lua::State* L) {
|
|||||||
static int l_is_vdamping(lua::State* L) {
|
static int l_is_vdamping(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
return lua::pushboolean(
|
return lua::pushboolean(
|
||||||
|
L, entity->getRigidbody().hitbox.verticalDamping > 0.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_get_vdamping(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
return lua::pushnumber(
|
||||||
L, entity->getRigidbody().hitbox.verticalDamping
|
L, entity->getRigidbody().hitbox.verticalDamping
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -70,7 +79,11 @@ static int l_is_vdamping(lua::State* L) {
|
|||||||
|
|
||||||
static int l_set_vdamping(lua::State* L) {
|
static int l_set_vdamping(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
entity->getRigidbody().hitbox.verticalDamping = lua::toboolean(L, 2);
|
if (lua::isboolean(L, 2)) {
|
||||||
|
entity->getRigidbody().hitbox.verticalDamping = lua::toboolean(L, 2);
|
||||||
|
} else {
|
||||||
|
entity->getRigidbody().hitbox.verticalDamping = lua::tonumber(L, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -144,6 +157,7 @@ const luaL_Reg rigidbodylib[] = {
|
|||||||
{"get_linear_damping", lua::wrap<l_get_linear_damping>},
|
{"get_linear_damping", lua::wrap<l_get_linear_damping>},
|
||||||
{"set_linear_damping", lua::wrap<l_set_linear_damping>},
|
{"set_linear_damping", lua::wrap<l_set_linear_damping>},
|
||||||
{"is_vdamping", lua::wrap<l_is_vdamping>},
|
{"is_vdamping", lua::wrap<l_is_vdamping>},
|
||||||
|
{"get_vdamping", lua::wrap<l_get_vdamping>},
|
||||||
{"set_vdamping", lua::wrap<l_set_vdamping>},
|
{"set_vdamping", lua::wrap<l_set_vdamping>},
|
||||||
{"is_grounded", lua::wrap<l_is_grounded>},
|
{"is_grounded", lua::wrap<l_is_grounded>},
|
||||||
{"is_crouching", lua::wrap<l_is_crouching>},
|
{"is_crouching", lua::wrap<l_is_crouching>},
|
||||||
|
|||||||
@ -54,7 +54,7 @@ struct Hitbox {
|
|||||||
glm::vec3 velocity;
|
glm::vec3 velocity;
|
||||||
float linearDamping = 0.5;
|
float linearDamping = 0.5;
|
||||||
float friction = 1.0f;
|
float friction = 1.0f;
|
||||||
bool verticalDamping = false;
|
float verticalDamping = 1.0f;
|
||||||
bool grounded = false;
|
bool grounded = false;
|
||||||
float gravityScale = 1.0f;
|
float gravityScale = 1.0f;
|
||||||
bool crouching = false;
|
bool crouching = false;
|
||||||
|
|||||||
@ -86,8 +86,8 @@ void PhysicsSolver::step(
|
|||||||
}
|
}
|
||||||
vel.x /= 1.0f + delta * linearDamping;
|
vel.x /= 1.0f + delta * linearDamping;
|
||||||
vel.z /= 1.0f + delta * linearDamping;
|
vel.z /= 1.0f + delta * linearDamping;
|
||||||
if (hitbox.verticalDamping) {
|
if (hitbox.verticalDamping > 0.0f) {
|
||||||
vel.y /= 1.0f + delta * linearDamping;
|
vel.y /= 1.0f + delta * linearDamping * hitbox.verticalDamping;
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user