forked from VoxeLibre/VoxeLibre
add random planar velocity when stopped
this seems to almost solve the problem of random standing.
This commit is contained in:
parent
d1a37f38b4
commit
cbd3e3264f
|
@ -2244,7 +2244,14 @@ local follow_flop = function(self)
|
||||||
|
|
||||||
return
|
return
|
||||||
elseif self.state == "flop" then
|
elseif self.state == "flop" then
|
||||||
self.state = "stand"
|
if not is_glider(self) then
|
||||||
|
self.state = "stand"
|
||||||
|
set_animation(self, "stand")
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
set_animation(self, "walk")
|
||||||
|
return
|
||||||
|
end
|
||||||
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
end
|
end
|
||||||
|
@ -2490,10 +2497,14 @@ local do_states = function(self, dtime)
|
||||||
or random(1, 100) <= 30
|
or random(1, 100) <= 30
|
||||||
or ( (self.fly and not self.keep_flying)
|
or ( (self.fly and not self.keep_flying)
|
||||||
or not self.fly ) then
|
or not self.fly ) then
|
||||||
|
if not is_glider(self) then
|
||||||
set_velocity(self, 0)
|
self.state = "stand"
|
||||||
self.state = "stand"
|
set_animation(self, "stand")
|
||||||
set_animation(self, "stand")
|
set_velocity(self, 0)
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
set_animation(self, "walk")
|
||||||
|
end
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
yaw = set_yaw(self, yaw + 0.78, 8)
|
yaw = set_yaw(self, yaw + 0.78, 8)
|
||||||
else
|
else
|
||||||
|
@ -2519,9 +2530,14 @@ local do_states = function(self, dtime)
|
||||||
if self.runaway_timer > 5
|
if self.runaway_timer > 5
|
||||||
or is_at_cliff_or_danger(self) then
|
or is_at_cliff_or_danger(self) then
|
||||||
self.runaway_timer = 0
|
self.runaway_timer = 0
|
||||||
set_velocity(self, 0)
|
if not is_glider(self) then
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
set_animation(self, "stand")
|
set_animation(self, "stand")
|
||||||
|
set_velocity(self, 0)
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
set_animation(self, "walk")
|
||||||
|
end
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
yaw = set_yaw(self, yaw + 0.78, 8)
|
yaw = set_yaw(self, yaw + 0.78, 8)
|
||||||
else
|
else
|
||||||
|
@ -2542,9 +2558,14 @@ local do_states = function(self, dtime)
|
||||||
or self.attack:get_hp() <= 0
|
or self.attack:get_hp() <= 0
|
||||||
or (self.attack:is_player() and mcl_mobs.invis[ self.attack:get_player_name() ]) then
|
or (self.attack:is_player() and mcl_mobs.invis[ self.attack:get_player_name() ]) then
|
||||||
|
|
||||||
self.state = "stand"
|
if not is_glider(self) then
|
||||||
set_velocity(self, 0)
|
self.state = "stand"
|
||||||
set_animation(self, "stand")
|
set_animation(self, "stand")
|
||||||
|
set_velocity(self, 0)
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
set_animation(self, "walk")
|
||||||
|
end
|
||||||
self.attack = nil
|
self.attack = nil
|
||||||
self.v_start = false
|
self.v_start = false
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
|
@ -3391,7 +3412,11 @@ local mob_staticdata = function(self)
|
||||||
self.remove_ok = true
|
self.remove_ok = true
|
||||||
self.attack = nil
|
self.attack = nil
|
||||||
self.following = nil
|
self.following = nil
|
||||||
self.state = "stand"
|
if not is_glider(self) then
|
||||||
|
self.state = "stand"
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
end
|
||||||
|
|
||||||
local tmp = {}
|
local tmp = {}
|
||||||
|
|
||||||
|
@ -3582,21 +3607,26 @@ end
|
||||||
|
|
||||||
local function check_ground(self) --return true if too close to the ground
|
local function check_ground(self) --return true if too close to the ground
|
||||||
local p = self.object:get_pos()
|
local p = self.object:get_pos()
|
||||||
local n = minetest.find_nodes_in_area_under_air(vector.offset(p,0,-self.desired_altitude-1,0),vector.offset(p,0,0,0),{"group:solid"})
|
local n = minetest.find_nodes_in_area_under_air(vector.offset(p,0,-self.desired_altitude-1,0),vector.offset(p,0,0,0),{"group:solid","group:liquid"})
|
||||||
if #n > 0 then
|
if #n > 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_random_velocity(self)
|
||||||
|
local v = self.object:get_velocity()
|
||||||
|
return vector.new(math.random(self.walk_velocity),v.y,math.random(self.walk_velocity))
|
||||||
|
end
|
||||||
|
|
||||||
local function descend(self)
|
local function descend(self)
|
||||||
local v = self.object:get_velocity()
|
local v = self.object:get_velocity()
|
||||||
local gs = get_speed_over_ground(self)
|
local gs = get_speed_over_ground(self)
|
||||||
local r = math.max(math.abs(self.fall_speed) - gs,1)
|
local r = math.max(math.abs(self.fall_speed) - gs,1)
|
||||||
--minetest.log("descend "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r))
|
--minetest.log("descend "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r))
|
||||||
if v.y > self.fall_speed then
|
if v.y > self.fall_speed then
|
||||||
self.object:set_velocity(vector.new(v.x,-r,v.z))
|
--self.object:set_velocity(vector.new(v.x,-r,v.z))
|
||||||
|
self.object:add_velocity(vector.new(0,-r/10,0))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function climb(self)
|
local function climb(self)
|
||||||
|
@ -3613,6 +3643,12 @@ end
|
||||||
local function check_flight(self,dtime)
|
local function check_flight(self,dtime)
|
||||||
if self.floater or not self.fly then return end --floaters don't need altitdude adjustment
|
if self.floater or not self.fly then return end --floaters don't need altitdude adjustment
|
||||||
--self.state = "walk"
|
--self.state = "walk"
|
||||||
|
local gs = get_speed_over_ground(self)
|
||||||
|
if gs < 1 then
|
||||||
|
local y = self.object:get_yaw()
|
||||||
|
self.object:set_yaw((y + math.random(-30,30)) % 360)
|
||||||
|
set_velocity(self,math.random(1,self.walk_velocity))
|
||||||
|
end
|
||||||
if not self.flap_timer and check_ground(self) then
|
if not self.flap_timer and check_ground(self) then
|
||||||
climb(self)
|
climb(self)
|
||||||
self.flap_timer = 0
|
self.flap_timer = 0
|
||||||
|
@ -3777,8 +3813,13 @@ local mob_step = function(self, dtime)
|
||||||
if is_at_water_danger(self) and self.state ~= "attack" then
|
if is_at_water_danger(self) and self.state ~= "attack" then
|
||||||
if random(1, 10) <= 6 then
|
if random(1, 10) <= 6 then
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
self.state = "stand"
|
if not is_glider(self) then
|
||||||
set_animation(self, "stand")
|
self.state = "stand"
|
||||||
|
set_animation(self, "stand")
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
set_animation(self, "walk")
|
||||||
|
end
|
||||||
yaw = yaw + random(-0.5, 0.5)
|
yaw = yaw + random(-0.5, 0.5)
|
||||||
yaw = set_yaw(self, yaw, 8)
|
yaw = set_yaw(self, yaw, 8)
|
||||||
end
|
end
|
||||||
|
@ -3827,9 +3868,14 @@ local mob_step = function(self, dtime)
|
||||||
follow_flop(self)
|
follow_flop(self)
|
||||||
|
|
||||||
if is_at_cliff_or_danger(self) then
|
if is_at_cliff_or_danger(self) then
|
||||||
set_velocity(self, 0)
|
if not is_glider(self) then
|
||||||
self.state = "stand"
|
set_velocity(self, 0)
|
||||||
set_animation(self, "stand")
|
self.state = "stand"
|
||||||
|
set_animation(self, "stand")
|
||||||
|
else
|
||||||
|
self.state = "walk"
|
||||||
|
set_animation(self, "walk")
|
||||||
|
end
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
yaw = set_yaw(self, yaw + 0.78, 8)
|
yaw = set_yaw(self, yaw + 0.78, 8)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue