Merge pull request 'Make spiders climb up walls, fix problems with mob following freaking out when under, fix spider collisionbox' (#1638) from jordan4ibanez/MineClone2:mineclone5 into mineclone5
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/1638mineclone5
commit
81315838d5
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
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
|
||||
|
|
|
@ -236,3 +236,11 @@ mobs.check_for_player_within_area = function(self, radius)
|
|||
--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
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue