From c9c2b874bea18253ee11135773baeda5ed00ed8d Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 11 Nov 2022 00:09:45 +0100 Subject: [PATCH] move relative animation speed to separate function --- mods/ENTITIES/mcl_mobs/api.lua | 21 +-------------------- mods/ENTITIES/mcl_mobs/effects.lua | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index c1402d3d1..0a3b7d38a 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -454,26 +454,7 @@ function mob_class:on_step(dtime) self:follow_flop() --set animation speed relitive to velocity - local v = self.object:get_velocity() - if v then - if self.frame_speed_multiplier then - local v2 = math.abs(v.x)+math.abs(v.z)*.833 - if not self.animation.walk_speed then - self.animation.walk_speed = 25 - end - if math.abs(v.x)+math.abs(v.z) > 0.5 then - self.object:set_animation_frame_speed((v2/math.max(1,self.run_velocity))*self.animation.walk_speed*self.frame_speed_multiplier) - else - self.object:set_animation_frame_speed(25) - end - end - - --set_speed - if self.acc then - self.object:add_velocity(self.acc) - end - end - + self:set_animation_speed() -- smooth rotation by ThomasMonroe314 if self._turn_to then diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index a58d1b095..d02b5058b 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -350,6 +350,27 @@ function mob_class:check_head_swivel() end end +function mob_class:set_animation_speed() + local v = self.object:get_velocity() + if v then + if self.frame_speed_multiplier then + local v2 = math.abs(v.x)+math.abs(v.z)*.833 + if not self.animation.walk_speed then + self.animation.walk_speed = 25 + end + if math.abs(v.x)+math.abs(v.z) > 0.5 then + self.object:set_animation_frame_speed((v2/math.max(1,self.run_velocity))*self.animation.walk_speed*self.frame_speed_multiplier) + else + self.object:set_animation_frame_speed(25) + end + end + --set_speed + if self.acc then + self.object:add_velocity(self.acc) + end + end +end + minetest.register_on_leaveplayer(function(player) local pn = player:get_player_name() if not active_particlespawners[pn] then return end