Remove hardcoded gravity from item entity, fix bouancy in environmental effects

This commit is contained in:
teknomunk 2024-04-03 06:48:01 +00:00
parent fbc57abbc8
commit bbdc0f00e3
3 changed files with 34 additions and 23 deletions

View File

@ -89,7 +89,6 @@ local function enable_physics(object, luaentity, ignore_check)
object:set_properties({
physical = true
})
object:set_acceleration(vector.new(0, -get_gravity(), 0))
end
end
@ -855,7 +854,6 @@ minetest.register_entity(":__builtin:item", {
self.object:set_armor_groups({ immortal = 1 })
-- self.object:set_velocity(vector.new(0, 2, 0))
self.object:set_acceleration(vector.new(0, -get_gravity(), 0))
self:set_item(self.itemstring)
end,

View File

@ -22,11 +22,11 @@ function mod.get_environment_effect(pos, vel, staticdata, mass)
end
end
if vector.length(v) > 0.01 or vector.length(a) > 0.01 then
return v,a
else
return -- nil,nil
end
-- Disable small effects
if vector.length(v) < 0.01 then v = nil end
if vector.length(a) < 0.01 then a = nil end
return v,a
end
function mod.apply_entity_environmental_physics(self, data)
@ -36,6 +36,9 @@ function mod.apply_entity_environmental_physics(self, data)
local vel = self.object:get_velocity()
local new_velocity,new_acceleration = mcl_physics.get_environment_effect(pos, vel, data, 1)
if new_velocity then print("new_velocity="..tostring(new_velocity)) end
if new_acceleration then print("new_acceleration="..tostring(new_acceleration)) end
-- Update entity states
self._flowing = data.flowing

View File

@ -5,36 +5,46 @@ mcl_physics = mod
dofile(modpath.."/api.lua")
-- Flowing water
-- TODO: move to Flowlib
local FLOW_SPEED = 1.39
local BOUANCY = 3
mod.register_environment_effect(function(pos, vel, staticdata)
-- Get the node and node definition
local node = minetest.get_node_or_nil(pos)
if not node then return end
local nodedef = minetest.registered_nodes[node.name]
if not nodedef then return end
local node = minetest.get_node_or_nil(pos); if not node then return end
local nodedef = minetest.registered_nodes[node.name]; if not nodedef then return end
-- Make sure we are in a liquid before continuing
local is_flowing = (nodedef.liquidtype == "flowing")
staticdata.flowing = is_flowing
if not is_flowing then
-- Apply decelleration if the entity moved from flowing water to
-- stationary water
if nodedef.liquidtype == "source" then
return nil,vector.new(
0 - vel.x * 0.9,
3 - vel.y * 0.9,
0 - vel.z * 0.9
)
end
return
end
if not is_flowing then return end
-- Get liquid flow direction
local vec = vector.multiply(flowlib.quick_flow(pos, node), FLOW_SPEED)
return vector.new(vec.x, -0.22, vec.z),nil
end)
-- Simple gravity and bouency
mod.register_environment_effect(function(pos, vel, staticdata)
-- Get the node and node definition
local node = minetest.get_node_or_nil(pos);
local nodedef = nil
if node then nodedef = minetest.registered_nodes[node.name] end
if nodedef and nodedef.liquidtype == "source" then
-- Apply decceleration and bouancy if the entity moved from flowing water to
-- stationary water
return nil,vector.new(
0 - vel.x * 0.9,
BOUANCY - vel.y * 0.9,
0 - vel.z * 0.9
)
else
local gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.81
return nil,vector.new(0,-gravity,0)
end
end)
-- Node effects
mod.register_environment_effect(function(pos, vel, staticdata)
local pos_r = vector.round(pos)