mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-25 02:00:21 +01:00
Fixed rotation bug
This commit is contained in:
parent
2bcd528e22
commit
6eb6e458af
104
api.lua
104
api.lua
@ -64,14 +64,12 @@ local abs = math.abs
|
|||||||
local min = math.min
|
local min = math.min
|
||||||
local max = math.max
|
local max = math.max
|
||||||
local atann = math.atan
|
local atann = math.atan
|
||||||
local atan2 = math.atan2
|
|
||||||
local random = math.random
|
local random = math.random
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
local atan = function(x)
|
local atan = function(x)
|
||||||
|
|
||||||
if x ~= x then
|
if x ~= x then
|
||||||
--error("atan bassed NaN")
|
--error("atan bassed NaN")
|
||||||
--print ("atan based NaN")
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return atann(x)
|
return atann(x)
|
||||||
@ -109,20 +107,25 @@ end
|
|||||||
set_yaw = function(self, yaw)
|
set_yaw = function(self, yaw)
|
||||||
|
|
||||||
if yaw ~= yaw then
|
if yaw ~= yaw then
|
||||||
|
print ("--- yaw nan")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.yaw = yaw + self.rotate
|
self.yaw = yaw -- + self.rotate
|
||||||
self.object:setyaw(self.yaw)
|
self.object:setyaw(self.yaw)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
set_velocity = function(self, v)
|
set_velocity = function(self, v)
|
||||||
|
|
||||||
|
local yaw = self.object:getyaw() + self.rotate
|
||||||
|
|
||||||
self.object:setvelocity({
|
self.object:setvelocity({
|
||||||
x = sin(self.yaw) * -v,
|
-- x = sin(self.yaw) * -v,
|
||||||
|
x = sin(yaw) * -v,
|
||||||
y = self.object:getvelocity().y,
|
y = self.object:getvelocity().y,
|
||||||
z = cos(self.yaw) * v
|
-- z = cos(self.yaw) * v
|
||||||
|
z = cos(yaw) * v
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -506,8 +509,11 @@ local function is_at_cliff(self)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir_x = -sin(self.yaw) * (self.collisionbox[4] + 0.5)
|
local yaw = self.object:getyaw()
|
||||||
local dir_z = cos(self.yaw) * (self.collisionbox[4] + 0.5)
|
-- local dir_x = -sin(self.yaw) * (self.collisionbox[4] + 0.5)
|
||||||
|
-- local dir_z = cos(self.yaw) * (self.collisionbox[4] + 0.5)
|
||||||
|
local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)
|
||||||
|
local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local ypos = pos.y + self.collisionbox[2] -- just above floor
|
local ypos = pos.y + self.collisionbox[2] -- just above floor
|
||||||
|
|
||||||
@ -642,6 +648,7 @@ do_jump = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
|
local yaw = self.object:getyaw()
|
||||||
|
|
||||||
-- what is mob standing on?
|
-- what is mob standing on?
|
||||||
pos.y = pos.y + self.collisionbox[2] - 0.2
|
pos.y = pos.y + self.collisionbox[2] - 0.2
|
||||||
@ -655,8 +662,10 @@ do_jump = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- where is front
|
-- where is front
|
||||||
local dir_x = -sin(self.yaw) * (self.collisionbox[4] + 0.5)
|
-- local dir_x = -sin(self.yaw) * (self.collisionbox[4] + 0.5)
|
||||||
local dir_z = cos(self.yaw) * (self.collisionbox[4] + 0.5)
|
-- local dir_z = cos(self.yaw) * (self.collisionbox[4] + 0.5)
|
||||||
|
local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5)
|
||||||
|
local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5)
|
||||||
|
|
||||||
-- what is in front of mob?
|
-- what is in front of mob?
|
||||||
local nod = node_ok({
|
local nod = node_ok({
|
||||||
@ -1029,7 +1038,8 @@ function smart_mobs(self, s, p, dist, dtime)
|
|||||||
|
|
||||||
else -- dig 2 blocks to make door toward player direction
|
else -- dig 2 blocks to make door toward player direction
|
||||||
|
|
||||||
local yaw1 = self.yaw + pi / 2
|
-- local yaw1 = self.yaw + pi / 2
|
||||||
|
local yaw1 = self.object:getyaw() + pi / 2
|
||||||
|
|
||||||
local p1 = {
|
local p1 = {
|
||||||
x = s.x + cos(yaw1),
|
x = s.x + cos(yaw1),
|
||||||
@ -1284,9 +1294,13 @@ local follow_flop = function(self)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
local yaw = atan2(vec.z, vec.x) - pi / 2
|
-- local yaw = atan2(vec.z, vec.x) - pi / 2
|
||||||
|
local yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
if p.x > s.x then yaw = yaw + pi end
|
||||||
|
|
||||||
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
|
|
||||||
-- anyone but standing npc's can move along
|
-- anyone but standing npc's can move along
|
||||||
if dist > self.reach
|
if dist > self.reach
|
||||||
@ -1363,7 +1377,7 @@ end
|
|||||||
-- execute current state (stand, walk, run, attacks)
|
-- execute current state (stand, walk, run, attacks)
|
||||||
local do_states = function(self, dtime)
|
local do_states = function(self, dtime)
|
||||||
|
|
||||||
local yaw = self.yaw -- 0
|
local yaw = 0 -- self.yaw
|
||||||
|
|
||||||
if self.state == "stand" then
|
if self.state == "stand" then
|
||||||
|
|
||||||
@ -1389,12 +1403,17 @@ local do_states = function(self, dtime)
|
|||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
yaw = atan2(vec.z, vec.x) - pi / 2
|
-- yaw = atan2(vec.z, vec.x) - pi / 2
|
||||||
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
|
if lp.x > s.x then yaw = yaw + pi end
|
||||||
else
|
else
|
||||||
yaw = random() * 2 * pi
|
-- yaw = random() * 2 * pi
|
||||||
|
yaw = (random(0, 360) - 180) / 180 * pi
|
||||||
end
|
end
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
end
|
end
|
||||||
|
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
@ -1453,9 +1472,13 @@ local do_states = function(self, dtime)
|
|||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
yaw = atan2(vec.z, vec.x) + pi / 2
|
-- yaw = atan2(vec.z, vec.x) + pi / 2
|
||||||
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
|
if lp.x > s.x then yaw = yaw + pi end
|
||||||
else
|
else
|
||||||
yaw = random() * 2 * pi
|
-- yaw = random() * 2 * pi
|
||||||
|
yaw = (random(0, 360) - 180) / 180 * pi
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -1465,17 +1488,22 @@ local do_states = function(self, dtime)
|
|||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
yaw = atan2(vec.z, vec.x) + pi / 2
|
-- yaw = atan2(vec.z, vec.x) + pi / 2
|
||||||
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
|
if lp.x > s.x then yaw = yaw + pi end
|
||||||
end
|
end
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
|
|
||||||
-- otherwise randomly turn
|
-- otherwise randomly turn
|
||||||
elseif random(1, 100) <= 30 then
|
elseif random(1, 100) <= 30 then
|
||||||
|
|
||||||
yaw = random() * 2 * pi
|
yaw = random() * 2 * pi
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- stand for great fall in front
|
-- stand for great fall in front
|
||||||
@ -1560,9 +1588,13 @@ local do_states = function(self, dtime)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
yaw = atan2(vec.z, vec.x) - pi / 2
|
-- yaw = atan2(vec.z, vec.x) - pi / 2
|
||||||
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
if p.x > s.x then yaw = yaw + pi end
|
||||||
|
|
||||||
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
|
|
||||||
if dist > self.reach then
|
if dist > self.reach then
|
||||||
|
|
||||||
@ -1724,9 +1756,13 @@ local do_states = function(self, dtime)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
yaw = atan2(vec.z, vec.x) - pi / 2
|
-- yaw = atan2(vec.z, vec.x) - pi / 2
|
||||||
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
if p.x > s.x then yaw = yaw + pi end
|
||||||
|
|
||||||
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
|
|
||||||
-- move towards enemy if beyond mob reach
|
-- move towards enemy if beyond mob reach
|
||||||
if dist > self.reach then
|
if dist > self.reach then
|
||||||
@ -1832,9 +1868,13 @@ local do_states = function(self, dtime)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
yaw = atan2(vec.z, vec.x) - pi / 2
|
-- yaw = atan2(vec.z, vec.x) - pi / 2
|
||||||
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
set_yaw(self, yaw)
|
if p.x > s.x then yaw = yaw + pi end
|
||||||
|
|
||||||
|
self.object:setyaw(yaw)
|
||||||
|
-- set_yaw(self, yaw)
|
||||||
|
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
|
|
||||||
@ -2233,7 +2273,8 @@ local mob_activate = function(self, staticdata, dtime_s, def)
|
|||||||
|
|
||||||
-- set anything changed above
|
-- set anything changed above
|
||||||
self.object:set_properties(self)
|
self.object:set_properties(self)
|
||||||
set_yaw(self, random() * 2 * pi)
|
-- set_yaw(self, random() * 2 * pi)
|
||||||
|
self.object:setyaw((random(0, 360) - 180) / 180 * pi)
|
||||||
update_tag(self)
|
update_tag(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2241,7 +2282,8 @@ end
|
|||||||
local mob_step = function(self, dtime)
|
local mob_step = function(self, dtime)
|
||||||
|
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local yaw = self.yaw
|
-- local yaw = self.yaw
|
||||||
|
local yaw = 0
|
||||||
|
|
||||||
-- when lifetimer expires remove mob (except npc and tamed)
|
-- when lifetimer expires remove mob (except npc and tamed)
|
||||||
if self.type ~= "npc"
|
if self.type ~= "npc"
|
||||||
@ -2373,8 +2415,8 @@ function mobs:register_mob(name, def)
|
|||||||
|
|
||||||
minetest.register_entity(name, {
|
minetest.register_entity(name, {
|
||||||
|
|
||||||
automatic_face_movement_dir = def.rotate and math.rad(def.rotate) or false,
|
--automatic_face_movement_dir = def.rotate and math.rad(def.rotate) or false,
|
||||||
automatic_face_movement_max_rotation_per_sec = -1,
|
--automatic_face_movement_max_rotation_per_sec = -1,
|
||||||
|
|
||||||
stepheight = def.stepheight or 0.6,
|
stepheight = def.stepheight or 0.6,
|
||||||
name = name,
|
name = name,
|
||||||
|
3265
api.lua_new
Normal file
3265
api.lua_new
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user