Change item on flowing water physics adding momentum and drag (experimental)

This commit is contained in:
wallabra 2022-02-09 02:44:39 -03:00
parent 07e000d077
commit ddbc3353a2
Signed by untrusted user: Gustavo6046
GPG Key ID: 5182FABAA5E139B3
1 changed files with 21 additions and 4 deletions

View File

@ -27,6 +27,8 @@ local mcl_item_entity = {}
local item_drop_settings = {} --settings table local item_drop_settings = {} --settings table
item_drop_settings.dug_buffer = 0.65 -- the warm up period before a dug item can be collected item_drop_settings.dug_buffer = 0.65 -- the warm up period before a dug item can be collected
item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting
item_drop_settings.fluid_flow_rate = 1.39 --the speed of a flowing fluid, used when computing push and drag forces of water on items; default is tuned to Minecraft
item_drop_settings.fluid_drag = 0.8 --how much drag water has on items (how quickly an item's motion will settle onto the water's flow speed)
item_drop_settings.radius_magnet = 2.0 --radius of item magnet. MUST BE LARGER THAN radius_collect! item_drop_settings.radius_magnet = 2.0 --radius of item magnet. MUST BE LARGER THAN radius_collect!
item_drop_settings.xp_radius_magnet = 7.25 --radius of xp magnet. MUST BE LARGER THAN radius_collect! item_drop_settings.xp_radius_magnet = 7.25 --radius of xp magnet. MUST BE LARGER THAN radius_collect!
item_drop_settings.radius_collect = 0.2 --radius of collection item_drop_settings.radius_collect = 0.2 --radius of collection
@ -778,11 +780,26 @@ minetest.register_entity(":__builtin:item", {
-- Just to make sure we don't manipulate the speed for no reason -- Just to make sure we don't manipulate the speed for no reason
if vec.x ~= 0 or vec.y ~= 0 or vec.z ~= 0 then if vec.x ~= 0 or vec.y ~= 0 or vec.z ~= 0 then
-- Minecraft Wiki: Flowing speed is "about 1.39 meters per second" -- Minecraft Wiki: Flowing speed is "about 1.39 meters per second"
local f = 1.39 local f = item_drop_settings.fluid_flow_rate --1.39
-- Set new item moving speed into the direciton of the liquid
local newv = vector.multiply(vec, f) -- Apply the force of the flowing liquid onto the item's velocity
local newv = vector.multiply(vec, f)
self.object:set_acceleration({x = 0, y = 0, z = 0}) self.object:set_acceleration({x = 0, y = 0, z = 0})
self.object:set_velocity({x = newv.x, y = -0.22, z = newv.z})
local oldvel = self.object:get_velocity() -- v is vector, vel is velocity
-- drag
newv.x = newv.x - (oldvel.x - newv.x) * item_drop_settings.fluid_drag
newv.y = newv.y - (oldvel.y - newv.y) * item_drop_settings.fluid_drag
newv.z = newv.z - (oldvel.z - newv.z) * item_drop_settings.fluid_drag
newv.y = newv.y + -0.22 -- (keep slight downward thrust from previous version of code)
-- NOTE: is there any particular reason we have this, anyway?
-- since fluid drag is now on, we could as well just
-- apply gravity here; drag will slow down the fall
-- realistically
self.object:set_velocity({x = oldvel.x + newv.x, y = oldvel.y + newv.y, z = oldvel.z + newv.z})
self.physical_state = true self.physical_state = true
self._flowing = true self._flowing = true