mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-04-30 13:51:41 -04:00
Fix spinning mobs
This commit is contained in:
parent
d7da61bbb5
commit
738be4d003
2 changed files with 19 additions and 8 deletions
15
api.lua
15
api.lua
|
@ -19,6 +19,7 @@ local function clamp(val, min, max)
|
||||||
end
|
end
|
||||||
|
|
||||||
local vec_dist = vector.distance
|
local vec_dist = vector.distance
|
||||||
|
local vec_multi = vector.multiply
|
||||||
local vec_equals = vector.equals
|
local vec_equals = vector.equals
|
||||||
local vec_add = vector.add
|
local vec_add = vector.add
|
||||||
|
|
||||||
|
@ -136,6 +137,7 @@ function creatura.get_node_def(node) -- Node can be name or pos
|
||||||
end
|
end
|
||||||
|
|
||||||
function creatura.get_ground_level(pos2, max_diff)
|
function creatura.get_ground_level(pos2, max_diff)
|
||||||
|
pos2.y = math.floor(pos2.y - 0.49)
|
||||||
local node = minetest.get_node(pos2)
|
local node = minetest.get_node(pos2)
|
||||||
local node_under = minetest.get_node({
|
local node_under = minetest.get_node({
|
||||||
x = pos2.x,
|
x = pos2.x,
|
||||||
|
@ -207,12 +209,15 @@ local moveable = creatura.is_pos_moveable
|
||||||
|
|
||||||
function creatura.fast_ray_sight(pos1, pos2, water)
|
function creatura.fast_ray_sight(pos1, pos2, water)
|
||||||
local ray = minetest.raycast(pos1, pos2, false, water or false)
|
local ray = minetest.raycast(pos1, pos2, false, water or false)
|
||||||
for pointed_thing in ray do
|
local pointed_thing = ray:next()
|
||||||
if pointed_thing.type == "node" then
|
while pointed_thing do
|
||||||
return false, vec_dist(pos1, pointed_thing.intersection_point), pointed_thing.ref
|
if pointed_thing.type == "node"
|
||||||
|
and creatura.get_node_def(pointed_thing.under).walkable then
|
||||||
|
return false, vec_dist(pos1, pointed_thing.intersection_point), pointed_thing.ref, pointed_thing.intersection_point
|
||||||
end
|
end
|
||||||
|
pointed_thing = ray:next()
|
||||||
end
|
end
|
||||||
return true, vec_dist(pos1, pos2)
|
return true, vec_dist(pos1, pos2), false, pos2
|
||||||
end
|
end
|
||||||
|
|
||||||
local fast_ray_sight = creatura.fast_ray_sight
|
local fast_ray_sight = creatura.fast_ray_sight
|
||||||
|
@ -432,7 +437,7 @@ function creatura.drop_items(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction)
|
function creatura.basic_punch_func(self, puncher, time_from_last_punch, tool_capabilities, direction, damage)
|
||||||
if not puncher then return end
|
if not puncher then return end
|
||||||
local tool = ""
|
local tool = ""
|
||||||
if puncher:is_player() then
|
if puncher:is_player() then
|
||||||
|
|
12
methods.lua
12
methods.lua
|
@ -30,6 +30,11 @@ local vec_add = vector.add
|
||||||
local yaw2dir = minetest.yaw_to_dir
|
local yaw2dir = minetest.yaw_to_dir
|
||||||
local dir2yaw = minetest.dir_to_yaw
|
local dir2yaw = minetest.dir_to_yaw
|
||||||
|
|
||||||
|
local function vec_raise(v, n)
|
||||||
|
if not v then return end
|
||||||
|
return {x = v.x, y = v.y + n, z = v.z}
|
||||||
|
end
|
||||||
|
|
||||||
--[[local function debugpart(pos, time, tex)
|
--[[local function debugpart(pos, time, tex)
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = pos,
|
pos = pos,
|
||||||
|
@ -198,7 +203,7 @@ creatura.register_movement_method("creatura:pathfind", function(self)
|
||||||
local function func(_self, goal, speed_factor)
|
local function func(_self, goal, speed_factor)
|
||||||
local pos = _self.object:get_pos()
|
local pos = _self.object:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
pos.y = creatura.get_ground_level(pos, 3).y
|
pos.y = pos.y + 0.5
|
||||||
-- Return true when goal is reached
|
-- Return true when goal is reached
|
||||||
if vec_dist(pos, goal) < box * 1.33 then
|
if vec_dist(pos, goal) < box * 1.33 then
|
||||||
_self:halt()
|
_self:halt()
|
||||||
|
@ -245,7 +250,7 @@ creatura.register_movement_method("creatura:theta_pathfind", function(self)
|
||||||
local function func(_self, goal, speed_factor)
|
local function func(_self, goal, speed_factor)
|
||||||
local pos = _self.object:get_pos()
|
local pos = _self.object:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
pos.y = creatura.get_ground_level(pos, 3).y
|
pos.y = pos.y + 0.5
|
||||||
-- Return true when goal is reached
|
-- Return true when goal is reached
|
||||||
if vec_dist(pos, goal) < box * 1.33 then
|
if vec_dist(pos, goal) < box * 1.33 then
|
||||||
_self:halt()
|
_self:halt()
|
||||||
|
@ -293,13 +298,14 @@ creatura.register_movement_method("creatura:obstacle_avoidance", function(self)
|
||||||
local function func(_self, goal, speed_factor)
|
local function func(_self, goal, speed_factor)
|
||||||
local pos = _self.object:get_pos()
|
local pos = _self.object:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
|
goal.y = creatura.get_ground_level(goal, 2).y
|
||||||
pos.y = creatura.get_ground_level(pos, 2).y
|
pos.y = creatura.get_ground_level(pos, 2).y
|
||||||
-- Return true when goal is reached
|
-- Return true when goal is reached
|
||||||
if vec_dist(pos, goal) < box * 1.33 then
|
if vec_dist(pos, goal) < box * 1.33 then
|
||||||
_self:halt()
|
_self:halt()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local steer_to = get_avoidance_dir(_self, goal)
|
--local steer_to = get_avoidance_dir(_self, goal)
|
||||||
-- Get movement direction
|
-- Get movement direction
|
||||||
local goal_dir = vec_dir(pos, goal)
|
local goal_dir = vec_dir(pos, goal)
|
||||||
if steer_to then
|
if steer_to then
|
||||||
|
|
Loading…
Add table
Reference in a new issue