mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-03-15 04:11:24 +00:00
More improvements
This commit is contained in:
parent
6c411bc6ac
commit
c202b2e7c3
7 changed files with 47 additions and 30 deletions
|
@ -226,4 +226,4 @@ function creatura.get_boid_angle(self, _boids, range)
|
||||||
table.insert(vert_params, vert_cohesion + (lift - vert_cohesion) * 0.1)
|
table.insert(vert_params, vert_cohesion + (lift - vert_cohesion) * 0.1)
|
||||||
end
|
end
|
||||||
return average_angle(params), average(vert_params)
|
return average_angle(params), average(vert_params)
|
||||||
end
|
end
|
||||||
|
|
60
methods.lua
60
methods.lua
|
@ -106,7 +106,7 @@ end]]
|
||||||
local get_node_def = creatura.get_node_def
|
local get_node_def = creatura.get_node_def
|
||||||
--local get_node_height = creatura.get_node_height_from_def
|
--local get_node_height = creatura.get_node_height_from_def
|
||||||
|
|
||||||
function creatura.get_collision_ranged(self, dir, range)
|
function creatura.get_collision_ranged(self, dir, range, water)
|
||||||
local pos, yaw = self.object:get_pos(), self.object:get_yaw()
|
local pos, yaw = self.object:get_pos(), self.object:get_yaw()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
local width = self.width + 0.1
|
local width = self.width + 0.1
|
||||||
|
@ -120,6 +120,7 @@ function creatura.get_collision_ranged(self, dir, range)
|
||||||
local height_half = self.height * 0.5
|
local height_half = self.height * 0.5
|
||||||
local center_y = pos.y + height_half
|
local center_y = pos.y + height_half
|
||||||
-- Loop
|
-- Loop
|
||||||
|
local n_def
|
||||||
local cos_yaw = cos(yaw)
|
local cos_yaw = cos(yaw)
|
||||||
local sin_yaw = sin(yaw)
|
local sin_yaw = sin(yaw)
|
||||||
local pos_x, pos_y, pos_z = ahead.x, ahead.y, ahead.z
|
local pos_x, pos_y, pos_z = ahead.x, ahead.y, ahead.z
|
||||||
|
@ -137,16 +138,26 @@ function creatura.get_collision_ranged(self, dir, range)
|
||||||
y = pos_y,
|
y = pos_y,
|
||||||
z = sin_yaw * ((pos_x + x) - pos_x) + pos_z
|
z = sin_yaw * ((pos_x + x) - pos_x) + pos_z
|
||||||
}
|
}
|
||||||
|
local step_flag = false
|
||||||
for y = 0, height, height / ceil(height) do
|
for y = 0, height, height / ceil(height) do
|
||||||
|
if y > self.height
|
||||||
|
and not step_flag then
|
||||||
|
break
|
||||||
|
end
|
||||||
pos2.y = pos_y + y
|
pos2.y = pos_y + y
|
||||||
if pos2.y - pos_y > (self.stepheight or 1.1)
|
n_def = get_node_def(pos2)
|
||||||
and get_node_def(pos2).walkable then
|
if n_def.walkable
|
||||||
local dist_dngr = (height_half - abs(center_y - pos2.y)) / height_half
|
or (water and (n_def.groups.liquid or 0) > 0) then
|
||||||
local field_dngr = vec_dot(dir, vec_normal(vec_dir(pos, pos2)))
|
if pos2.y - pos_y > (self.stepheight or 1.1) then
|
||||||
local ttl_dngr = dist_dngr + field_dngr
|
local dist_dngr = (height_half - abs(center_y - pos2.y)) / height_half
|
||||||
if ttl_dngr > danger then
|
local field_dngr = vec_dot(dir, vec_normal(vec_dir(pos, pos2)))
|
||||||
danger = ttl_dngr
|
local ttl_dngr = dist_dngr + field_dngr
|
||||||
collision = pos2
|
if ttl_dngr > danger then
|
||||||
|
danger = ttl_dngr
|
||||||
|
collision = pos2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
step_flag = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -263,13 +274,16 @@ local steer_directions = {
|
||||||
return output_dir
|
return output_dir
|
||||||
end]]
|
end]]
|
||||||
|
|
||||||
local function get_collision_single(pos)
|
local function get_collision_single(pos, water)
|
||||||
local pos2 = {x = pos.x, y = pos.y, z = pos.z}
|
local pos2 = {x = pos.x, y = pos.y, z = pos.z}
|
||||||
if get_node_def(pos2).walkable then
|
local n_def = get_node_def(pos2)
|
||||||
|
if n_def.walkable
|
||||||
|
or (water and (n_def.groups.liquid or 0) > 0) then
|
||||||
pos2.y = pos.y + 1
|
pos2.y = pos.y + 1
|
||||||
local col_max = get_node_def(pos2).walkable
|
n_def = get_node_def(pos2)
|
||||||
|
local col_max = n_def.walkable or (water and (n_def.groups.liquid or 0) > 0)
|
||||||
pos2.y = pos.y - 1
|
pos2.y = pos.y - 1
|
||||||
local col_min = col_max and get_node_def(pos2).walkable
|
local col_min = col_max and (n_def.walkable or (water and (n_def.groups.liquid or 0) > 0))
|
||||||
if col_min then
|
if col_min then
|
||||||
return pos
|
return pos
|
||||||
else
|
else
|
||||||
|
@ -279,13 +293,13 @@ local function get_collision_single(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function creatura.get_context_steering(self, goal, range)
|
function creatura.get_context_steering(self, goal, range, water)
|
||||||
local pos, yaw = self.object:get_pos(), self.object:get_yaw()
|
local pos, yaw = self.object:get_pos(), self.object:get_yaw()
|
||||||
if not pos or not yaw then return end
|
if not pos or not yaw then return end
|
||||||
range = range or 8; if range < 2 then range = 2 end
|
range = range or 8; if range < 2 then range = 2 end
|
||||||
local width, height = self.width, self.height
|
local width, height = self.width, self.height
|
||||||
local dir2goal = vec_normal(vec_dir(pos, goal))
|
local dir2goal = vec_normal(vec_dir(pos, goal))
|
||||||
local output_dir = {x = 0, y = 0, z = 0}
|
local output_dir = {x = 0, y = dir2goal.y, z = 0}
|
||||||
pos.y = (pos.y + height * 0.5)
|
pos.y = (pos.y + height * 0.5)
|
||||||
|
|
||||||
local collision
|
local collision
|
||||||
|
@ -299,14 +313,14 @@ function creatura.get_context_steering(self, goal, range)
|
||||||
if interest > 0 then
|
if interest > 0 then
|
||||||
if width <= 0.5
|
if width <= 0.5
|
||||||
and height <= 1 then
|
and height <= 1 then
|
||||||
collision = get_collision_single(vec_add(pos, dir))
|
collision = get_collision_single(vec_add(pos, dir), water)
|
||||||
else
|
else
|
||||||
_, collision = creatura.get_collision_ranged(self, dir, range)
|
_, collision = creatura.get_collision_ranged(self, dir, range, water)
|
||||||
end
|
end
|
||||||
if collision then
|
if collision then
|
||||||
dir2col = vec_normal(vec_dir(pos, collision))
|
dir2col = vec_normal(vec_dir(pos, collision))
|
||||||
local dist2col = vec_dist(pos, collision) - width
|
local dist2col = vec_dist(pos, collision) - width
|
||||||
dir.y = dir2col.y * -1
|
dir.y = ((dir2col.y * -1) + dir2goal.y * 1.5) / 2
|
||||||
local dot_weight = vec_dot(dir2col, dir2goal)
|
local dot_weight = vec_dot(dir2col, dir2goal)
|
||||||
local dist_weight = (range - dist2col) / range
|
local dist_weight = (range - dist2col) / range
|
||||||
interest = interest - dot_weight
|
interest = interest - dot_weight
|
||||||
|
@ -373,6 +387,7 @@ function creatura.action_fallover(self)
|
||||||
local zrot = 0
|
local zrot = 0
|
||||||
local init = false
|
local init = false
|
||||||
local dir = 1
|
local dir = 1
|
||||||
|
local rot = self.object:get_rotation()
|
||||||
local function func(_self)
|
local function func(_self)
|
||||||
if not init then
|
if not init then
|
||||||
_self:animate("stand")
|
_self:animate("stand")
|
||||||
|
@ -381,10 +396,11 @@ function creatura.action_fallover(self)
|
||||||
end
|
end
|
||||||
init = true
|
init = true
|
||||||
end
|
end
|
||||||
local rot = _self.object:get_rotation()
|
rot = _self.object:get_rotation()
|
||||||
local goal = (pi * 0.5) * dir
|
local goal = (pi * 0.5) * dir
|
||||||
local dif = abs(rot.z - goal)
|
local step = _self.dtime
|
||||||
zrot = rot.z + (dif * dir) * 0.15
|
if step > 0.5 then step = 0.5 end
|
||||||
|
zrot = zrot + (pi * dir) * step
|
||||||
_self.object:set_rotation({x = rot.x, y = rot.y, z = zrot})
|
_self.object:set_rotation({x = rot.x, y = rot.y, z = zrot})
|
||||||
if (dir > 0 and zrot >= goal)
|
if (dir > 0 and zrot >= goal)
|
||||||
or (dir < 0 and zrot <= goal) then return true end
|
or (dir < 0 and zrot <= goal) then return true end
|
||||||
|
@ -577,4 +593,4 @@ creatura.register_movement_method("creatura:context_based_steering", function(se
|
||||||
_self:turn_to(dir2yaw(steer_to or vec_dir(pos, goal)), turn_rate)
|
_self:turn_to(dir2yaw(steer_to or vec_dir(pos, goal)), turn_rate)
|
||||||
end
|
end
|
||||||
return func
|
return func
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -459,7 +459,7 @@ end
|
||||||
|
|
||||||
function mob:set_scale(x)
|
function mob:set_scale(x)
|
||||||
local def = minetest.registered_entities[self.name]
|
local def = minetest.registered_entities[self.name]
|
||||||
local scale = def.visual_size
|
local scale = def.visual_size or {x = 1, y = 1}
|
||||||
local box = def.collisionbox
|
local box = def.collisionbox
|
||||||
local new_box = {}
|
local new_box = {}
|
||||||
for k, v in ipairs(box) do
|
for k, v in ipairs(box) do
|
||||||
|
@ -559,7 +559,8 @@ end
|
||||||
|
|
||||||
local function is_group_in_table(tbl, name)
|
local function is_group_in_table(tbl, name)
|
||||||
for _, v in pairs(tbl) do
|
for _, v in pairs(tbl) do
|
||||||
if minetest.get_item_group(name, v:split(":")[2]) > 0 then
|
if type(v) == "string"
|
||||||
|
and minetest.get_item_group(name, v:split(":")[2]) > 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
10
spawning.lua
10
spawning.lua
|
@ -41,8 +41,8 @@ end
|
||||||
|
|
||||||
function creatura.register_spawn_egg(name, col1, col2, inventory_image) -- deprecated
|
function creatura.register_spawn_egg(name, col1, col2, inventory_image) -- deprecated
|
||||||
if col1 and col2 then
|
if col1 and col2 then
|
||||||
local base = "(creatura_spawning_crystal.png^[multiply:#" .. col1 .. ")"
|
local base = "(creatura_spawning_crystal_primary.png^[multiply:#" .. col1 .. ")"
|
||||||
local spots = "(creatura_spawning_crystal_overlay.png^[multiply:#" .. col2 .. ")"
|
local spots = "(creatura_spawning_crystal_secondary.png^[multiply:#" .. col2 .. ")"
|
||||||
inventory_image = base .. "^" .. spots
|
inventory_image = base .. "^" .. spots
|
||||||
end
|
end
|
||||||
local mod_name = name:split(":")[1]
|
local mod_name = name:split(":")[1]
|
||||||
|
@ -73,8 +73,8 @@ function creatura.register_spawn_item(name, def)
|
||||||
local inventory_image
|
local inventory_image
|
||||||
if not def.inventory_image
|
if not def.inventory_image
|
||||||
and def.col1 and def.col2 then
|
and def.col1 and def.col2 then
|
||||||
local base = "(creatura_spawning_crystal.png^[multiply:#" .. def.col1 .. ")"
|
local base = "(creatura_spawning_crystal_primary.png^[multiply:#" .. def.col1 .. ")"
|
||||||
local spots = "(creatura_spawning_crystal_overlay.png^[multiply:#" .. def.col2 .. ")"
|
local spots = "(creatura_spawning_crystal_secondary.png^[multiply:#" .. def.col2 .. ")"
|
||||||
inventory_image = base .. "^" .. spots
|
inventory_image = base .. "^" .. spots
|
||||||
end
|
end
|
||||||
local mod_name = name:split(":")[1]
|
local mod_name = name:split(":")[1]
|
||||||
|
@ -658,4 +658,4 @@ function creatura.register_abm_spawn(mob, def)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
BIN
textures/creatura_spawning_crystal_secondary.png
Normal file
BIN
textures/creatura_spawning_crystal_secondary.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 698 B |
Loading…
Add table
Reference in a new issue