Add knockback for mobs

This commit is contained in:
Elias Åström 2020-04-18 12:19:18 +02:00
parent 6315490b14
commit 92ab90fd1b

View File

@ -322,17 +322,18 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance)
-- Punch entity with damage depending on explosion exposure and -- Punch entity with damage depending on explosion exposure and
-- distance to explosion -- distance to explosion
local exposure = count / N_EXPOSURE_RAYS local exposure = count / N_EXPOSURE_RAYS
local punch_vec = vector.subtract(pos, opos) local punch_vec = vector.subtract(opos, pos)
local punch_dir = vector.normalize(punch_vec) local punch_dir = vector.normalize(punch_vec)
local impact = (1 - vector.length(punch_vec) / punch_radius) * exposure local impact = (1 - vector.length(punch_vec) / punch_radius) * exposure
if impact < 0 then if impact < 0 then
impact = 0 impact = 0
end end
local damage = math.floor((impact * impact + impact) * 7 * strength + 1) local damage = math.floor((impact * impact + impact) * 7 * strength + 1)
obj:punch(obj, nil, { damage_groups = { fleshy = damage } }, punch_dir) obj:punch(obj, 10, { damage_groups = { full_punch_interval = 1,
fleshy = damage, knockback = impact * 20.0 } }, punch_dir)
if obj:is_player() then if obj:is_player() then
obj:add_player_velocity(vector.multiply(punch_dir, -exposure * 20)) obj:add_player_velocity(vector.multiply(punch_dir, impact * 20))
end end
end end
end end