1
0
Fork 0

Make mobs jump properly

mineclone5
jordan4ibanez 2021-04-15 15:34:07 -04:00
parent 6cb6d714c9
commit d07d0ae31c
2 changed files with 54 additions and 0 deletions

View File

@ -1,5 +1,14 @@
local math_random = math.random
local vector_multiply = vector.multiply
local minetest_yaw_to_dir = minetest.yaw_to_dir
local minetest_get_item_group = minetest.get_item_group
local minetest_get_node = minetest.get_node
-- execute current state (stand, walk, run, attacks)
-- returns true if mob has died
local do_states = function(self, dtime)
@ -17,6 +26,35 @@ local do_states = function(self, dtime)
end
--check if a mob needs to jump
local jump_check = function(self,dtime)
local pos = self.object:get_pos()
pos.y = pos.y + 0.1
local dir = minetest_yaw_to_dir(self.yaw)
local collisionbox = self.object:get_properties().collisionbox
local radius = collisionbox[4] + 0.5
vector_multiply(dir, radius)
local test_dir = vector.add(pos,dir)
if minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 then
print("jump")
mobs.jump(self)
end
end
mobs.mob_step = function(self, dtime)
--do not continue if non-existent
@ -34,6 +72,8 @@ mobs.mob_step = function(self, dtime)
do_states(self, dtime)
jump_check(self)
mobs.movement_rotation_lock(self)
@ -201,4 +241,6 @@ mobs.mob_step = function(self, dtime)
end
end
]]--
self.old_velocity = self.object:get_velocity()
end

View File

@ -51,4 +51,16 @@ mobs.get_velocity = function(self)
end
return 0
end
--make mobs jump
mobs.jump = function(self, velocity)
if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then
return
end
velocity = velocity or 5
self.object:add_velocity(vector_new(0,velocity,0))
end