Add in chicken slow falling
This commit is contained in:
parent
0895666407
commit
4efec1ef58
|
@ -355,6 +355,7 @@ function mobs:register_mob(name, def)
|
|||
hostile_cooldown = def.hostile_cooldown or 15,
|
||||
tilt_fly = def.tilt_fly,
|
||||
tilt_swim = def.tilt_swim,
|
||||
fall_slow = def.fall_slow,
|
||||
-- End of MCL2 extensions
|
||||
|
||||
on_spawn = def.on_spawn,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
local math_random = math.random
|
||||
local math_pi = math.pi
|
||||
local math_floor = math.floor
|
||||
local math_round = math.round
|
||||
|
||||
local vector_multiply = vector.multiply
|
||||
local vector_add = vector.add
|
||||
|
@ -22,6 +24,12 @@ local quick_rotate = function(self,dtime)
|
|||
end
|
||||
end
|
||||
|
||||
--a simple helper function for rounding
|
||||
--http://lua-users.org/wiki/SimpleRound
|
||||
function round2(num, numDecimalPlaces)
|
||||
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
_ _
|
||||
|
@ -89,6 +97,21 @@ local land_state_execution = function(self,dtime)
|
|||
float_now = true
|
||||
end
|
||||
|
||||
--make slow falling mobs fall slow
|
||||
if self.fall_slow then
|
||||
if self.object:get_velocity().y < 0 then
|
||||
--lua is acting really weird so we have to help it
|
||||
if round2(self.object:get_acceleration().y, 1) == -self.gravity then
|
||||
self.object:set_acceleration(vector_new(0,0,0))
|
||||
mobs.mob_fall_slow(self)
|
||||
end
|
||||
else
|
||||
if round2(self.object:get_acceleration().y, 1) == 0 then
|
||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.state == "stand" then
|
||||
|
||||
--do animation
|
||||
|
|
|
@ -113,8 +113,36 @@ mobs.jump = function(self, velocity)
|
|||
self.object:add_velocity(vector_new(0,velocity,0))
|
||||
end
|
||||
|
||||
--make mobs fall slowly
|
||||
mobs.mob_fall_slow = function(self)
|
||||
|
||||
local current_velocity = self.object:get_velocity()
|
||||
|
||||
local goal_velocity = {
|
||||
x = 0,
|
||||
y = -2,
|
||||
z = 0,
|
||||
}
|
||||
|
||||
|
||||
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||
|
||||
new_velocity_addition.x = 0
|
||||
new_velocity_addition.z = 0
|
||||
|
||||
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
||||
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
||||
end
|
||||
|
||||
new_velocity_addition.x = 0
|
||||
new_velocity_addition.z = 0
|
||||
|
||||
--smooths out mobs a bit
|
||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
||||
self.object:add_velocity(new_velocity_addition)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
|
|
|
@ -18,6 +18,7 @@ mobs:register_mob("mobs_mc:chicken", {
|
|||
xp_max = 3,
|
||||
collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.69, 0.2},
|
||||
runaway = true,
|
||||
fall_slow = true,
|
||||
floats = 1,
|
||||
visual = "mesh",
|
||||
mesh = "mobs_mc_chicken.b3d",
|
||||
|
|
Loading…
Reference in New Issue