Начинающий
- Статус
- Оффлайн
- Регистрация
- 26 Авг 2021
- Сообщения
- 13
- Реакции
- 0
делаю свой гренейд предикшион, получилось так, что если трейс прилетает в игрока, он как-то фейлится и неправильно записывает позицию предикта, без игрока все идеально, подскажите добрые люди, как это пофиксить?
Код:
for tick = 0, math.huge do
if velocity:length() < 0.1 then
break
end
local half_gravity = gravity * tickinterval * 0.5
local move_step = vector(
velocity.x * tickinterval,
velocity.y * tickinterval,
(velocity.z - half_gravity) * tickinterval
)
velocity.z = velocity.z - gravity * tickinterval
local next_pos = pos + move_step
local trace = utils.trace_hull(
pos, next_pos, mins, maxs, m_owner, mask
)
local surface_elasticity = 1
local ent = entity.get(trace.entindex)
local is_player = ent ~= nil and ent:is_player()
if is_player then
surface_elasticity = 0.3
end
if ent ~= nil then
if is_breakable(ent[0]) then
velocity = velocity * 0.4
end
end
if trace.fraction < 1 then
local normal = trace.plane.normal
if is_molotov and max_slope_cos < normal.z then
pos:init(trace.end_pos:unpack())
return true, tick, false
end
velocity = velocity - normal * velocity:dot(normal) * 2
if math.abs(velocity.x) < 0.1 then velocity.x = 0 end
if math.abs(velocity.y) < 0.1 then velocity.y = 0 end
if math.abs(velocity.z) < 0.1 then velocity.z = 0 end
velocity = velocity * 0.45 * surface_elasticity
local vel_sqr = velocity:lengthsqr()
if normal.z > 0.7 and vel_sqr > 96000 then
local dot_val = velocity:normalized():dot(normal)
if dot_val > 0.5 then
velocity = velocity * (1.5 - dot_val)
end
end
if vel_sqr < 400 then
velocity = vector(0, 0, 0)
end
if velocity:lengthsqr() > 0 then
local end_pos = trace.end_pos
local push = velocity * ((1 - trace.fraction) * tickinterval)
trace = utils.trace_hull(end_pos, end_pos + push, mins, maxs, m_owner, 33570827)
if trace.start_solid or is_player then
local end_pos = trace.end_pos
tr = utils.trace_line(end_pos - push, end_pos + push, m_owner, 540683)
end
end
next_pos = trace.end_pos
end
pos = next_pos
end