From 82153c2af97318111e207f14375cb1466dc18603 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:50:08 -0700 Subject: [PATCH 1/4] make mob movment more fluid --- mods/ENTITIES/mcl_mobs/api.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index a17e7466d..5452dd96a 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -336,18 +336,18 @@ local set_velocity = function(self, v) -- halt mob if it has been ordered to stay if self.order == "stand" or self.order == "sit" then - self.object:set_velocity({x = 0, y = 0, z = 0}) - return + self.acc=vector.new(0,0,0) + return end local yaw = (self.object:get_yaw() or 0) + self.rotate local vv = self.object:get_velocity() if vv then - self.object:set_velocity({ - x = (sin(yaw) * -v) + c_x, - y = vv.y, - z = (cos(yaw) * v) + c_y, - }) + self.acc={ + x = ((sin(yaw) * -v) + c_x)*.3, + y = 0, + z = ((cos(yaw) * v) + c_y)*.3, + } end end @@ -3887,6 +3887,21 @@ local mob_step = function(self, dtime) --Mob following code. follow_flop(self) + + --set animation speed relitive to velocity + local v = self.object:get_velocity() + local v2 = abs(v.x)+abs(v.z)*.833 + self.object:set_animation_frame_speed((v2/self.walk_velocity)*25) + + --diffuse object velocity + self.object:set_velocity({x = v.x*.8, y = v.y, z = v.z*.8}) + + --set_speed + if self.acc then + self.object:add_velocity(self.acc) + end + + -- smooth rotation by ThomasMonroe314 if self._turn_to then set_yaw(self, self._turn_to, .1) From ba127ecb12b075b3f17f87b3ba90b5de38c0375d Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Thu, 13 Oct 2022 19:12:23 -0700 Subject: [PATCH 2/4] fine-tune mob velocity --- mods/ENTITIES/mcl_mobs/api.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 5452dd96a..b98c4836c 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -344,9 +344,9 @@ local set_velocity = function(self, v) local vv = self.object:get_velocity() if vv then self.acc={ - x = ((sin(yaw) * -v) + c_x)*.3, + x = ((sin(yaw) * -v) + c_x)*.27, y = 0, - z = ((cos(yaw) * v) + c_y)*.3, + z = ((cos(yaw) * v) + c_y)*.27, } end end @@ -536,6 +536,7 @@ local set_animation = function(self, anim, fixed_frame) anim = "jockey" end + if flight_check(self) and self.fly and anim == "walk" then anim = "fly" end self._current_animation = self._current_animation or "" @@ -3887,18 +3888,20 @@ local mob_step = function(self, dtime) --Mob following code. follow_flop(self) - --set animation speed relitive to velocity local v = self.object:get_velocity() - local v2 = abs(v.x)+abs(v.z)*.833 - self.object:set_animation_frame_speed((v2/self.walk_velocity)*25) + if v then + local v2 = abs(v.x)+abs(v.z)*.833 + self.object:set_animation_frame_speed((v2/self.walk_velocity)*25) - --diffuse object velocity - self.object:set_velocity({x = v.x*.8, y = v.y, z = v.z*.8}) - --set_speed - if self.acc then - self.object:add_velocity(self.acc) + --diffuse object velocity + self.object:set_velocity({x = v.x*.85, y = v.y, z = v.z*.85}) + + --set_speed + if self.acc then + self.object:add_velocity(self.acc) + end end From 44ba08cb8be1d2484b8950e9125d9e93aadef3e1 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:31:18 -0700 Subject: [PATCH 3/4] make die animation more smooth for all mobs --- mods/ENTITIES/mcl_mobs/api.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index b98c4836c..8a42d6cbb 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1014,9 +1014,6 @@ local check_for_death = function(self, cause, cmi_cause) length = max(frames / speed, 0) + DEATH_DELAY set_animation(self, "die") else - local rot = self.object:get_rotation() - rot.z = pi/2 - self.object:set_rotation(rot) length = 1 + DEATH_DELAY set_animation(self, "stand", true) end @@ -3850,6 +3847,12 @@ local mob_step = function(self, dtime) end end + if self.state and self.state=="die" or check_for_death(self) then + local rot = self.object:get_rotation() + rot.z = ((pi/2-rot.z)*.2)+rot.z + self.object:set_rotation(rot) + end + if not player_in_active_range(self) then set_animation(self, "stand", true) self.object:set_velocity(vector.new(0,0,0)) From f242655b1349ab921b3609559f6e05587081612f Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:50:36 -0700 Subject: [PATCH 4/4] make mobs predict jumps before even getting too close to a bock. --- mods/ENTITIES/mcl_mobs/api.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 8a42d6cbb..f6b23fbd6 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1409,9 +1409,16 @@ local do_jump = function(self) return false end + local v = self.object:get_velocity() + local v2 = abs(v.x)+abs(v.z)*.833 + local jump_c_multiplier = 1 + if v2/self.walk_velocity/2>1 then + jump_c_multiplier = v2/self.walk_velocity/2 + end + -- where is front - local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) - local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)*jump_c_multiplier+.4 + local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)*jump_c_multiplier+.4 -- what is in front of mob? nod = node_ok({