From cbd3e3264f86487d0eceb8470fdc5cbf40a12f13 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 24 May 2022 00:24:57 +0200 Subject: [PATCH] add random planar velocity when stopped this seems to almost solve the problem of random standing. --- mods/ENTITIES/mcl_mobs/api.lua | 86 ++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 2a1981bf9..e8e06964e 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2244,7 +2244,14 @@ local follow_flop = function(self) return 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}) set_velocity(self, 0) end @@ -2490,10 +2497,14 @@ local do_states = function(self, dtime) or random(1, 100) <= 30 or ( (self.fly and not self.keep_flying) or not self.fly ) then - - set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") + if not is_glider(self) then + self.state = "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 yaw = set_yaw(self, yaw + 0.78, 8) else @@ -2519,9 +2530,14 @@ local do_states = function(self, dtime) if self.runaway_timer > 5 or is_at_cliff_or_danger(self) then self.runaway_timer = 0 - set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") + if not is_glider(self) then + self.state = "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 yaw = set_yaw(self, yaw + 0.78, 8) else @@ -2542,9 +2558,14 @@ local do_states = function(self, dtime) or self.attack:get_hp() <= 0 or (self.attack:is_player() and mcl_mobs.invis[ self.attack:get_player_name() ]) then - self.state = "stand" - set_velocity(self, 0) - set_animation(self, "stand") + if not is_glider(self) then + self.state = "stand" + set_animation(self, "stand") + set_velocity(self, 0) + else + self.state = "walk" + set_animation(self, "walk") + end self.attack = nil self.v_start = false self.timer = 0 @@ -3391,7 +3412,11 @@ local mob_staticdata = function(self) self.remove_ok = true self.attack = nil self.following = nil - self.state = "stand" + if not is_glider(self) then + self.state = "stand" + else + self.state = "walk" + end local tmp = {} @@ -3582,21 +3607,26 @@ end local function check_ground(self) --return true if too close to the ground 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 return true 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 v = self.object:get_velocity() local gs = get_speed_over_ground(self) local r = math.max(math.abs(self.fall_speed) - gs,1) --minetest.log("descend "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r)) 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 local function climb(self) @@ -3613,6 +3643,12 @@ end local function check_flight(self,dtime) if self.floater or not self.fly then return end --floaters don't need altitdude adjustment --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 climb(self) 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 random(1, 10) <= 6 then set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") + if not is_glider(self) then + self.state = "stand" + set_animation(self, "stand") + else + self.state = "walk" + set_animation(self, "walk") + end yaw = yaw + random(-0.5, 0.5) yaw = set_yaw(self, yaw, 8) end @@ -3827,9 +3868,14 @@ local mob_step = function(self, dtime) follow_flop(self) if is_at_cliff_or_danger(self) then - set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") + if not is_glider(self) then + set_velocity(self, 0) + self.state = "stand" + set_animation(self, "stand") + else + self.state = "walk" + set_animation(self, "walk") + end local yaw = self.object:get_yaw() or 0 yaw = set_yaw(self, yaw + 0.78, 8) end