1
0
Fork 0

Merge pull request 'Clean up crash code and convert to new style vectors' (#3703) from cleanup_crash_code into master

Reviewed-on: MineClone2/MineClone2#3703
This commit is contained in:
ancientmarinerdev 2023-05-11 19:25:20 +00:00
commit ede98cda80
3 changed files with 27 additions and 18 deletions

View File

@ -830,16 +830,18 @@ local function clear_aggro(self)
end
function mob_class:do_states_attack (dtime)
local yaw = self.object:get_yaw() or 0
local s = self.object:get_pos()
local p = self.attack:get_pos() or s
self.timer = self.timer + dtime
if self.timer > 100 then
self.timer = 1
end
local s = self.object:get_pos()
if not s then return end
local p = self.attack:get_pos() or s
local yaw = self.object:get_yaw() or 0
-- stop attacking if player invisible or out of range
if not self.attack
or not self.attack:get_pos()
@ -1141,7 +1143,13 @@ function mob_class:do_states_attack (dtime)
if math.random(40) == 1 then
self.strafe_direction = self.strafe_direction*-1
end
self.acc = vector.add(vector.multiply(vector.rotate_around_axis(vector.direction(s, p), vector.new(0,1,0), self.strafe_direction), 0.3*self.walk_velocity), stay_away_from_player)
local dir = vector.rotate_around_axis(vector.direction(s, p), vector.new(0,1,0), self.strafe_direction)
local dir2 = vector.multiply(dir, 0.3 * self.walk_velocity)
if dir2 and stay_away_from_player then
self.acc = vector.add(dir2, stay_away_from_player)
end
else
self:set_velocity( 0)
end

View File

@ -219,8 +219,9 @@ function mob_class:is_at_cliff_or_danger(can_jump_cliff)
local ypos = pos.y + self.collisionbox[2] -- just above floor
local free_fall, blocker = minetest.line_of_sight(
{x = pos.x + dir_x, y = ypos, z = pos.z + dir_z},
{x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z})
vector.new(pos.x + dir_x, ypos, pos.z + dir_z),
vector.new(pos.x + dir_x, ypos - self.fear_height, pos.z + dir_z))
if free_fall then
return true
else
@ -262,8 +263,9 @@ function mob_class:is_at_water_danger(can_jump_cliff)
local ypos = pos.y + self.collisionbox[2] -- just above floor
local free_fall, blocker = minetest.line_of_sight(
{x = pos.x + dir_x, y = ypos, z = pos.z + dir_z},
{x = pos.x + dir_x, y = ypos - 3, z = pos.z + dir_z})
vector.new(pos.x + dir_x, ypos, pos.z + dir_z),
vector.new(pos.x + dir_x, ypos - 3, pos.z + dir_z))
if free_fall then
return true
else

View File

@ -198,6 +198,8 @@ end
-- move mob in facing direction
function mob_class:set_velocity(v)
if not v then return end
local c_x, c_y = 0, 0
-- can mob be pushed, if so calculate direction
@ -207,18 +209,15 @@ function mob_class:set_velocity(v)
-- halt mob if it has been ordered to stay
if self.order == "stand" or self.order == "sit" then
self.acc=vector.new(0,0,0)
self.acc = vector.zero()
return
end
local yaw = (self.object:get_yaw() or 0) + self.rotate
local vv = self.object:get_velocity()
if vv then
self.acc={
x = ((math.sin(yaw) * -v) + c_x)*.27,
y = 0,
z = ((math.cos(yaw) * v) + c_y)*.27,
}
if vv and yaw then
self.acc = vector.new(((math.sin(yaw) * -v) + c_x) * .27, 0, ((math.cos(yaw) * v) + c_y) * .27)
end
end