Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1945: apply rotation before applying speed #1973

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions mods/lord/Core/projectiles/src/projectiles/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
35 changes: 22 additions & 13 deletions mods/lord/Core/projectiles/src/projectiles/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -316,4 +324,5 @@ end

return {
register_projectile_entity = register_projectile_entity,
get_rotation_pattern = get_rotation_pattern,
}
Loading