forked from VoxeLibre/VoxeLibre
Cleanup self.acc code and convert to new style vectors
This commit is contained in:
parent
0185609b01
commit
8092fd573c
|
@ -830,16 +830,18 @@ local function clear_aggro(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mob_class:do_states_attack (dtime)
|
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
|
self.timer = self.timer + dtime
|
||||||
if self.timer > 100 then
|
if self.timer > 100 then
|
||||||
self.timer = 1
|
self.timer = 1
|
||||||
end
|
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
|
-- stop attacking if player invisible or out of range
|
||||||
if not self.attack
|
if not self.attack
|
||||||
or not self.attack:get_pos()
|
or not self.attack:get_pos()
|
||||||
|
@ -1141,7 +1143,13 @@ function mob_class:do_states_attack (dtime)
|
||||||
if math.random(40) == 1 then
|
if math.random(40) == 1 then
|
||||||
self.strafe_direction = self.strafe_direction*-1
|
self.strafe_direction = self.strafe_direction*-1
|
||||||
end
|
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
|
else
|
||||||
self:set_velocity( 0)
|
self:set_velocity( 0)
|
||||||
end
|
end
|
||||||
|
|
|
@ -198,6 +198,8 @@ end
|
||||||
|
|
||||||
-- move mob in facing direction
|
-- move mob in facing direction
|
||||||
function mob_class:set_velocity(v)
|
function mob_class:set_velocity(v)
|
||||||
|
if not v then return end
|
||||||
|
|
||||||
local c_x, c_y = 0, 0
|
local c_x, c_y = 0, 0
|
||||||
|
|
||||||
-- can mob be pushed, if so calculate direction
|
-- 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
|
-- halt mob if it has been ordered to stay
|
||||||
if self.order == "stand" or self.order == "sit" then
|
if self.order == "stand" or self.order == "sit" then
|
||||||
self.acc=vector.new(0,0,0)
|
self.acc = vector.zero()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local yaw = (self.object:get_yaw() or 0) + self.rotate
|
local yaw = (self.object:get_yaw() or 0) + self.rotate
|
||||||
local vv = self.object:get_velocity()
|
local vv = self.object:get_velocity()
|
||||||
if vv then
|
|
||||||
self.acc={
|
if vv and yaw then
|
||||||
x = ((math.sin(yaw) * -v) + c_x)*.27,
|
self.acc = vector.new(((math.sin(yaw) * -v) + c_x) * .27, 0, ((math.cos(yaw) * v) + c_y) * .27)
|
||||||
y = 0,
|
|
||||||
z = ((math.cos(yaw) * v) + c_y)*.27,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue