Advertisement
Guest User

MT

a guest
Jan 27th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. minetest.calculate_knockback(function(player, hitter, time_from_last_punch, tool_capabilities, dir, distance, damage)
  2.     local in_bed = beds.player
  3.     local name = player:get_player_name()
  4.  
  5.     if damage == 0 or player:get_armor_groups().immortal or in_bed[name] then
  6.         return 0.0
  7.     end
  8.  
  9.     local m = 8
  10.     -- solve m - m*e^(k*4) = 4 for k
  11.     local k = -0.17328
  12.     local res = m - m * math.exp(k * damage)
  13.  
  14.     if distance < 2.0 then
  15.         res = res * 1.1 -- more knockback when closer
  16.     elseif distance > 4.0 then
  17.         res = res * 0.9 -- less when far away
  18.     end
  19.     return res
  20. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement