add random planar velocity when stopped

this seems to almost solve the problem of random standing.
This commit is contained in:
cora 2022-05-24 00:24:57 +02:00
parent d1a37f38b4
commit cbd3e3264f
1 changed files with 66 additions and 20 deletions

View File

@ -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