From 807fb6966d747550da276b264e8e3bf376b332ab Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 24 Apr 2021 20:27:37 -0400 Subject: [PATCH] Make spiders climb up walls, fix problems with mob following freaking out when under, fix spider collisionbox --- mods/ENTITIES/mcl_mobs/api/api.lua | 7 ++++++ .../mcl_mobs/api/mob_functions/ai.lua | 4 +++- .../attack_type_instructions.lua | 16 +++++++++++-- .../api/mob_functions/environment.lua | 8 +++++++ .../mcl_mobs/api/mob_functions/movement.lua | 23 +++++++++++++++++++ mods/ENTITIES/mobs_mc/spider.lua | 10 +++++--- 6 files changed, 62 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 0d1a347c5..81c88a064 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -325,6 +325,13 @@ function mobs:register_mob(name, def) projectile_cooldown_min = def.projectile_cooldown_min or 2, projectile_cooldown_max = def.projectile_cooldown_max or 6, skittish = def.skittish, + + minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath + + --for spiders + always_climb = def.always_climb, + + --despawn mechanic variables lifetimer_reset = 30, --30 seconds lifetimer = 30, --30 seconds diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index b5af5f533..ee7ca0ecc 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -204,9 +204,11 @@ local land_state_execution = function(self,dtime) --check distance local distance_from_follow_person = vector_distance(self.object:get_pos(), self.following_person:get_pos()) + local distance_2d = mobs.get_2d_distance(self.object:get_pos(), self.following_person:get_pos()) --don't push the player if too close - if self.follow_distance < distance_from_follow_person then + --don't spin around randomly + if self.follow_distance < distance_from_follow_person and self.minimum_follow_distance < distance_2d then mobs.set_mob_animation(self, "run") mobs.set_velocity(self,self.run_velocity) 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 7907f8c47..20de36c40 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 @@ -120,9 +120,15 @@ mobs.punch_attack_walk = function(self,dtime) return end - mobs.set_yaw_while_attacking(self) + local distance_from_attacking = mobs.get_2d_distance(self.object:get_pos(), self.attacking:get_pos()) - mobs.set_velocity(self, self.run_velocity) + if distance_from_attacking >= self.minimum_follow_distance then + mobs.set_velocity(self, self.run_velocity) + else + mobs.set_velocity(self, 0) + end + + mobs.set_yaw_while_attacking(self) mobs.set_mob_animation(self, "run") @@ -130,10 +136,16 @@ mobs.punch_attack_walk = function(self,dtime) --check for nodes to jump over --explosive mobs will just ride against walls for now local node_in_front_of = mobs.jump_check(self) + if node_in_front_of == 1 then mobs.jump(self) end + --mobs that can climb over stuff + if self.always_climb and node_in_front_of > 0 then + mobs.climb(self) + end + --auto reset punch_timer if not self.punch_timer then diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua index 5b5dc5d47..5656a1668 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua @@ -235,4 +235,12 @@ mobs.check_for_player_within_area = function(self, radius) end --did not find a player return(false) +end + + +--a simple helper function for mobs following +mobs.get_2d_distance = function(pos1,pos2) + pos1.y = 0 + pos2.y = 0 + return(vector_distance(pos1, pos2)) end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua index 819df6353..916563832 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua @@ -16,6 +16,7 @@ local minetest_dir_to_yaw = minetest.dir_to_yaw local DEFAULT_JUMP_HEIGHT = 5 local DEFAULT_FLOAT_SPEED = 4 +local DEFAULT_CLIMB_SPEED = 3 @@ -41,6 +42,28 @@ mobs.float = function(self) end end +--this is a generic climb function +mobs.climb = function(self) + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = 0, + y = DEFAULT_CLIMB_SPEED, + z = 0, + } + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + new_velocity_addition.x = 0 + new_velocity_addition.z = 0 + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + --[[ diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index 95179310b..09cbba5a7 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -16,17 +16,21 @@ local spider = { type = "monster", spawn_class = "hostile", passive = false, + hostile = true, + always_climb = true, docile_by_day = true, attack_type = "punch", - pathfinding = 1, + punch_timer_cooloff = 0.5, + rotate = 270, damage = 2, reach = 2, hp_min = 16, hp_max = 16, xp_min = 5, xp_max = 5, + eye_height = 0.475, armor = {fleshy = 100, arthropod = 100}, - collisionbox = {-0.7, -0.01, -0.7, 0.7, 0.89, 0.7}, + collisionbox = {-0.45, 0, -0.45, 0.45, 0.9, 0.45}, visual = "mesh", mesh = "mobs_mc_spider.b3d", textures = { @@ -43,7 +47,7 @@ local spider = { distance = 16, }, walk_velocity = 1.3, - run_velocity = 2.8, + run_velocity = 2.75, --spider can become extremely difficult if any higher jump = true, jump_height = 4, view_range = 16,