mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-12 04:33:15 +01:00
fix delay=0 in combat code, tune turning parameters
This commit is contained in:
parent
995f1386db
commit
67055959c6
@ -12,15 +12,7 @@ local enable_pathfinding = true
|
|||||||
|
|
||||||
local TIME_TO_FORGET_TARGET = 15
|
local TIME_TO_FORGET_TARGET = 15
|
||||||
|
|
||||||
local atann = math.atan
|
local atan2 = math.atan2
|
||||||
local function atan(x)
|
|
||||||
if not x or x ~= x then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return atann(x)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- check if daytime and also if mob is docile during daylight hours
|
-- check if daytime and also if mob is docile during daylight hours
|
||||||
function mob_class:day_docile()
|
function mob_class:day_docile()
|
||||||
@ -925,10 +917,8 @@ function mob_class:do_states_attack (dtime)
|
|||||||
if self.attack_type == "explode" then
|
if self.attack_type == "explode" then
|
||||||
|
|
||||||
if target_line_of_sight then
|
if target_line_of_sight then
|
||||||
local vec = { x = p.x - s.x, z = p.z - s.z }
|
yaw = -atan2(p.x - s.x, p.z - s.z) - self.rotate
|
||||||
yaw = (atan(vec.z / vec.x) +math.pi/ 2) - self.rotate
|
yaw = self:set_yaw(yaw, 1, dtime)
|
||||||
if p.x > s.x then yaw = yaw +math.pi end
|
|
||||||
yaw = self:set_yaw( yaw, 0, dtime)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local node_break_radius = self.explosion_radius or 1
|
local node_break_radius = self.explosion_radius or 1
|
||||||
@ -1081,16 +1071,8 @@ function mob_class:do_states_attack (dtime)
|
|||||||
p = {x = p1.x, y = p1.y, z = p1.z}
|
p = {x = p1.x, y = p1.y, z = p1.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
local vec = {
|
yaw = -atan2(p.x - s.x, p.z - s.z) - self.rotate
|
||||||
x = p.x - s.x,
|
yaw = self:set_yaw(yaw, 1, dtime)
|
||||||
z = p.z - s.z
|
|
||||||
}
|
|
||||||
|
|
||||||
yaw = (atan(vec.z / vec.x) + math.pi / 2) - self.rotate
|
|
||||||
|
|
||||||
if p.x > s.x then yaw = yaw + math.pi end
|
|
||||||
|
|
||||||
yaw = self:set_yaw( yaw, 0, dtime)
|
|
||||||
|
|
||||||
-- move towards enemy if beyond mob reach
|
-- move towards enemy if beyond mob reach
|
||||||
if dist > self.reach then
|
if dist > self.reach then
|
||||||
@ -1171,18 +1153,14 @@ function mob_class:do_states_attack (dtime)
|
|||||||
p.y = p.y - .5
|
p.y = p.y - .5
|
||||||
s.y = s.y + .5
|
s.y = s.y + .5
|
||||||
|
|
||||||
local dist = vector.distance(p, s)
|
|
||||||
local vec = {
|
local vec = {
|
||||||
x = p.x - s.x,
|
x = p.x - s.x,
|
||||||
y = p.y - s.y,
|
y = p.y - s.y,
|
||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
local dist = (vec.x^2 + vec.y^2 + vec.z^2)^0.5
|
||||||
yaw = (atan(vec.z / vec.x) +math.pi/ 2) - self.rotate
|
yaw = -atan2(vec.x, vec.z) - self.rotate
|
||||||
|
yaw = self:set_yaw(yaw, 1, dtime)
|
||||||
if p.x > s.x then yaw = yaw +math.pi end
|
|
||||||
|
|
||||||
yaw = self:set_yaw( yaw, 0, dtime)
|
|
||||||
|
|
||||||
local stay_away_from_player = vector.zero()
|
local stay_away_from_player = vector.zero()
|
||||||
|
|
||||||
@ -1252,12 +1230,11 @@ function mob_class:do_states_attack (dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5
|
|
||||||
-- offset makes shoot aim accurate
|
-- offset makes shoot aim accurate
|
||||||
vec.y = vec.y + self.shoot_offset
|
vec.y = vec.y + self.shoot_offset
|
||||||
vec.x = vec.x * (v / amount)
|
vec.x = vec.x * (v / dist)
|
||||||
vec.y = vec.y * (v / amount)
|
vec.y = vec.y * (v / dist)
|
||||||
vec.z = vec.z * (v / amount)
|
vec.z = vec.z * (v / dist)
|
||||||
if self.shoot_arrow then
|
if self.shoot_arrow then
|
||||||
vec = vector.normalize(vec)
|
vec = vector.normalize(vec)
|
||||||
self:shoot_arrow(p, vec)
|
self:shoot_arrow(p, vec)
|
||||||
|
@ -354,7 +354,7 @@ function mob_class:env_danger_movement_checks(player_in_active_range)
|
|||||||
self:set_animation("stand")
|
self:set_animation("stand")
|
||||||
end
|
end
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
self:set_yaw(yaw + PIHALF * (random() - 0.5), 6)
|
self:set_yaw(yaw + PIHALF * (random() - 0.5), 10)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -367,7 +367,7 @@ function mob_class:env_danger_movement_checks(player_in_active_range)
|
|||||||
self:set_animation("stand")
|
self:set_animation("stand")
|
||||||
end
|
end
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
yaw = self:set_yaw(yaw + PIHALF * (random() - 0.5), 6)
|
yaw = self:set_yaw(yaw + PI * (random() - 0.5), 10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -473,7 +473,7 @@ function mob_class:do_jump()
|
|||||||
self.jump_count = (self.jump_count or 0) + 1
|
self.jump_count = (self.jump_count or 0) + 1
|
||||||
if self.jump_count == 4 then
|
if self.jump_count == 4 then
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
yaw = self:set_yaw(yaw + PIHALF * (random() - 0.5), 8)
|
yaw = self:set_yaw(yaw + PI * (random() - 0.5), 8)
|
||||||
self.jump_count = 0
|
self.jump_count = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -924,7 +924,7 @@ function mob_class:do_states_walk()
|
|||||||
if logging then
|
if logging then
|
||||||
minetest.log("action", "[mcl_mobs] "..self.name.." facing a wall, turning.")
|
minetest.log("action", "[mcl_mobs] "..self.name.." facing a wall, turning.")
|
||||||
end
|
end
|
||||||
yaw = self:set_yaw(yaw + PIHALF * (random() - 0.5), 6)
|
yaw = self:set_yaw(yaw + PI * (random() - 0.5), 6)
|
||||||
-- otherwise randomly turn
|
-- otherwise randomly turn
|
||||||
elseif random() <= 0.3 then
|
elseif random() <= 0.3 then
|
||||||
yaw = self:set_yaw(yaw + PIHALF * (random() - 0.5), 10)
|
yaw = self:set_yaw(yaw + PIHALF * (random() - 0.5), 10)
|
||||||
@ -973,8 +973,8 @@ function mob_class:do_states_stand(player_in_active_range)
|
|||||||
and self.facing_fence ~= true
|
and self.facing_fence ~= true
|
||||||
and random(1, 100) <= self.walk_chance then
|
and random(1, 100) <= self.walk_chance then
|
||||||
if self:is_at_cliff_or_danger() then
|
if self:is_at_cliff_or_danger() then
|
||||||
yaw = yaw + PIHALF * (random() - 0.5)
|
yaw = yaw + PI * (random() - 0.5)
|
||||||
yaw = self:set_yaw(yaw, 8)
|
yaw = self:set_yaw(yaw, 10)
|
||||||
else
|
else
|
||||||
self:set_velocity(self.walk_velocity)
|
self:set_velocity(self.walk_velocity)
|
||||||
self.state = "walk"
|
self.state = "walk"
|
||||||
@ -997,7 +997,7 @@ function mob_class:do_states_runaway()
|
|||||||
self:set_velocity(0)
|
self:set_velocity(0)
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
self:set_animation("stand")
|
self:set_animation("stand")
|
||||||
yaw = self:set_yaw(yaw + PI * (random() - 0.5), 8)
|
yaw = self:set_yaw(yaw + PI * (random() + 0.5), 8)
|
||||||
else
|
else
|
||||||
self:set_velocity( self.run_velocity)
|
self:set_velocity( self.run_velocity)
|
||||||
self:set_animation( "run")
|
self:set_animation( "run")
|
||||||
|
@ -283,17 +283,16 @@ function mob_class:check_smooth_rotation(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local delay = self.delay
|
local delay = self.delay
|
||||||
if delay and delay > 0 then
|
|
||||||
local yaw = self.object:get_yaw() or 0
|
local yaw = self.object:get_yaw() or 0
|
||||||
local target_yaw = self.target_yaw
|
local target_yaw = self.target_yaw
|
||||||
if delay == 1 then
|
if delay and delay > 1 then
|
||||||
yaw = target_yaw
|
|
||||||
else
|
|
||||||
local dif = (target_yaw - yaw + PI) % TWOPI - PI
|
local dif = (target_yaw - yaw + PI) % TWOPI - PI
|
||||||
yaw = (yaw + dif / delay) % TWOPI
|
yaw = (yaw + dif / delay) % TWOPI
|
||||||
|
self.delay = delay - 1
|
||||||
|
else
|
||||||
|
yaw = target_yaw
|
||||||
end
|
end
|
||||||
|
|
||||||
self.delay = delay - 1
|
|
||||||
if self.shaking then
|
if self.shaking then
|
||||||
yaw = yaw + (random() * 2 - 1) / 72 * dtime
|
yaw = yaw + (random() * 2 - 1) / 72 * dtime
|
||||||
end
|
end
|
||||||
@ -304,7 +303,6 @@ function mob_class:check_smooth_rotation(dtime)
|
|||||||
--end
|
--end
|
||||||
--self:update_roll()
|
--self:update_roll()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- global function to set mob yaw
|
-- global function to set mob yaw
|
||||||
function mcl_mobs.yaw(self, yaw, delay, dtime)
|
function mcl_mobs.yaw(self, yaw, delay, dtime)
|
||||||
|
Loading…
Reference in New Issue
Block a user