1
0
Fork 0

Implement basic fall damage

This commit is contained in:
jordan4ibanez 2021-04-25 16:43:23 -04:00
parent 7e3b69348e
commit 555935ff3d
3 changed files with 19 additions and 27 deletions

View File

@ -187,6 +187,11 @@ local land_state_execution = function(self,dtime)
end
end
--calculate fall damage
if self.fall_damage then
mobs.calculate_fall_damage(self)
end
if self.state == "stand" then
--do animation

View File

@ -279,33 +279,6 @@ local falling = function(self, pos)
end
else
-- fall damage onto solid ground
if self.fall_damage == 1
and self.object:get_velocity().y == 0 then
local d = (self.old_y or 0) - self.object:get_pos().y
if d > 5 then
local add = minetest_get_item_group(self.standing_on, "fall_damage_add_percent")
local damage = d - 5
if add ~= 0 then
damage = damage + damage * (add/100)
end
damage = math_floor(damage)
if damage > 0 then
self.health = self.health - damage
effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil)
if check_for_death(self, "fall", {type = "fall"}) then
return true
end
end
end
self.old_y = self.object:get_pos().y
end
end
end

View File

@ -15,6 +15,8 @@ local vector_distance = vector.distance
local table_copy = table.copy
local math_abs = math.abs
-- default function when mobs are blown up with TNT
local do_tnt = function(obj, damage)
@ -244,3 +246,15 @@ mobs.get_2d_distance = function(pos1,pos2)
pos2.y = 0
return(vector_distance(pos1, pos2))
end
-- fall damage onto solid ground
mobs.calculate_fall_damage = function(self)
if self.old_velocity and self.old_velocity.y < -7 and self.object:get_velocity().y == 0 then
local vel = self.object:get_velocity()
if vel then
local damage = math_abs(self.old_velocity.y + 7) * 2
self.pause_timer = 0.4
self.health = self.health - damage
end
end
end