diff --git a/mods/lord/Core/archery/src/archery/processor/processing_api.lua b/mods/lord/Core/archery/src/archery/processor/processing_api.lua index ec31671d1..356e482dc 100644 --- a/mods/lord/Core/archery/src/archery/processor/processing_api.lua +++ b/mods/lord/Core/archery/src/archery/processor/processing_api.lua @@ -119,12 +119,15 @@ local function projectile_shoot(shooter, projectile_stack, power, forced_directi local projectile_reg = projectiles.get_projectiles()[projectile_item] local projectile_entity = minetest.add_entity(projectile_pos, projectile_reg.entity_name) - projectile_entity:add_velocity(vector.multiply(look_dir, projectile_reg.entity_reg.max_speed * power)) + local initial_vel = vector.multiply(look_dir, projectile_reg.entity_reg.max_speed * power) + local rotation_formula = projectile_reg.entity_reg.rotation_formula + projectile_entity:set_rotation(projectiles.get_rotation_pattern(rotation_formula, initial_vel)) + projectile_entity:get_luaentity()._rotation_formula = rotation_formula + projectile_entity:add_velocity(initial_vel) projectile_entity:set_acceleration(vector.new(0, -GRAVITY, 0)) projectile_entity:get_luaentity()._shooter = shooter projectile_entity:get_luaentity()._projectile_stack = projectile_stack projectile_entity:get_luaentity()._remove_on_object_hit = projectile_reg.entity_reg.remove_on_object_hit - projectile_entity:get_luaentity()._rotation_formula = projectile_reg.entity_reg.rotation_formula return true end diff --git a/mods/lord/Core/projectiles/src/projectiles/api.lua b/mods/lord/Core/projectiles/src/projectiles/api.lua index c85dccfb2..8bf9b2582 100644 --- a/mods/lord/Core/projectiles/src/projectiles/api.lua +++ b/mods/lord/Core/projectiles/src/projectiles/api.lua @@ -126,7 +126,8 @@ end return { - explode_area = explode_area, - register_projectile = register_projectile, - get_projectiles = function() return registered_projectiles end, + explode_area = explode_area, + register_projectile = register_projectile, + get_rotation_pattern = entity.get_rotation_pattern, + get_projectiles = function() return registered_projectiles end, } diff --git a/mods/lord/Core/projectiles/src/projectiles/entity.lua b/mods/lord/Core/projectiles/src/projectiles/entity.lua index fb36909d8..42e58ba90 100644 --- a/mods/lord/Core/projectiles/src/projectiles/entity.lua +++ b/mods/lord/Core/projectiles/src/projectiles/entity.lua @@ -2,6 +2,25 @@ local math_pi, math_arctan, math_sqrt = math.pi, math.atan2, math.sqrt +local function get_rotation_pattern(rotation_type, vel) + if not rotation_type or type(rotation_type) ~= "string" then + rotation_type = "pointed" + end + local rotation_patterns = { + pointed = { + x = 0, + y = math_pi + math_arctan(vel.z, vel.x), + z = math_arctan(vel.y, math_sqrt(vel.z * vel.z + vel.x * vel.x)) + }, + rolling = { + x = 0, + y = -math_pi*2 + math_arctan(vel.z, vel.x), + z = -math_arctan(vel.y, math_sqrt(vel.z * vel.z + vel.x * vel.x)) + }, + } + return rotation_patterns[rotation_type] +end + -- Update projectile life timer --- @param projectile LuaEntity projectile entity --- @param dtime number time passed from the last call @@ -200,19 +219,8 @@ local function flight_processing(projectile, environment, rotation_formula) texture = particle_texture, }) end - local rot = { - pointed = { - x = 0, - y = math_pi + math_arctan(vel.z, vel.x), - z = math_arctan(vel.y, math_sqrt(vel.z * vel.z + vel.x * vel.x)) - }, - rolling = { - x = 0, - y = -math_pi*2 + math_arctan(vel.z, vel.x), - z = -math_arctan(vel.y, math_sqrt(vel.z * vel.z + vel.x * vel.x)) - }, - } - projectile.object:set_rotation(rot[rotation_formula or "pointed"]) + + projectile.object:set_rotation(get_rotation_pattern(rotation_formula, vel)) end end @@ -316,4 +324,5 @@ end return { register_projectile_entity = register_projectile_entity, + get_rotation_pattern = get_rotation_pattern, }