From a73e5b57c02275a37b98dc9c80cf35a8c782d9f7 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 24 Apr 2021 22:14:25 -0400 Subject: [PATCH] Make pitch movement for fly/swim mobs more dynamic and make ghasts randomly fly around when attacking --- mods/ENTITIES/mcl_mobs/api/api.lua | 1 + .../mcl_mobs/api/mob_functions/ai.lua | 4 +- .../attack_type_instructions.lua | 46 +++++++++++++++---- mods/ENTITIES/mobs_mc/ghast.lua | 1 + 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 3a1fa8bffb..d1e5a081ce 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -329,6 +329,7 @@ function mobs:register_mob(name, def) minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath memory = 0, -- memory timer if chasing/following + fly_random_while_attack = def.fly_random_while_attack, --for spiders always_climb = def.always_climb, diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index d8993ee507..0fe18c3f20 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -481,7 +481,7 @@ local swim_state_execution = function(self,dtime) self.yaw = (math_random() * (math.pi * 2)) --create a truly random pitch, since there is no easy access to pitch math that I can find - self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)] + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] end --do animation @@ -626,7 +626,7 @@ local fly_state_execution = function(self,dtime) self.yaw = (math_random() * (math.pi * 2)) --create a truly random pitch, since there is no easy access to pitch math that I can find - self.pitch = math_random() * random_pitch_multiplier[math_random(1,2)] + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] end --do animation diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua index 20de36c409..0df4a42f9b 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua @@ -279,6 +279,8 @@ ______ _ _ _ _ |__/ ]]-- +local random_pitch_multiplier = {-1,1} + mobs.projectile_attack_fly = function(self, dtime) --this needs an exception @@ -287,18 +289,41 @@ mobs.projectile_attack_fly = function(self, dtime) return end - local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + --this is specifically for random ghast movement + if self.fly_random_while_attack then + + --enable rotation locking + mobs.movement_rotation_lock(self) + + self.walk_timer = self.walk_timer - dtime + + --reset the walk timer + if self.walk_timer <= 0 then + --re-randomize the walk timer + self.walk_timer = math.random(1,6) + math.random() + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + --create a truly random pitch, since there is no easy access to pitch math that I can find + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] + end - if distance_from_attacking >= self.reach then - mobs.set_yaw_while_attacking(self) - mobs.set_pitch_while_attacking(self) mobs.set_fly_velocity(self, self.run_velocity) - mobs.set_mob_animation(self,"run") + else + mobs.set_yaw_while_attacking(self) - mobs.set_pitch_while_attacking(self) - mobs.set_fly_velocity(self, 0) - mobs.set_mob_animation(self,"stand") + + local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + + if distance_from_attacking >= self.reach then + mobs.set_pitch_while_attacking(self) + mobs.set_fly_velocity(self, self.run_velocity) + mobs.set_mob_animation(self,"run") + else + mobs.set_pitch_while_attacking(self) + mobs.set_fly_velocity(self, 0) + mobs.set_mob_animation(self,"stand") + end end @@ -313,6 +338,11 @@ mobs.projectile_attack_fly = function(self, dtime) --shoot if self.projectile_timer <= 0 then + + if self.fly_random_while_attack then + mobs.set_yaw_while_attacking(self) + self.walk_timer = 0 + end --reset timer self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max) mobs.shoot_projectile(self) diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index c1434f2010..7fa8f7da87 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -15,6 +15,7 @@ mobs:register_mob("mobs_mc:ghast", { spawn_class = "hostile", group_attack = true, hostile = true, + fly_random_while_attack = true, hp_min = 10, hp_max = 10, rotate = 270,