рассчитай recoveryspeed для того чтобы время восстановления было 400 мс local events =…
- User
рассчитай recovery_speed для того чтобы время восстановления было 400 мс
local events = require 'lib.samp.events'
-- Configuration local CONFIG = { recoil = { strength = 0.04, recovery_speed = 0.075 }, animation = { duration = 0.05 }, }
-- State variables local state = { cursor = { x = 0, y = 0 }, firing = { active = false, start_time = nil, start_pos = { x = 0, y = 0 }, target_pos = { x = 0, y = 0 } }, time = { last = nil } }
function main() repeat wait(0) until isSampAvailable() wait(-1) end
function events.onSendBulletSync() state.firing = { active = true, start_time = os.clock(), start_pos = { x = state.cursor.x, y = state.cursor.y }, target_pos = { x = state.cursor.x + CONFIG.recoil.strength, y = state.cursor.y + (math.random() * CONFIG.recoil.strength - CONFIG.recoil.strength/2) * 0.1 } } end
function onD3DPresent() local current_time = os.clock() local delta_time = current_time - (state.time.last or current_time) state.time.last = current_time
local camera = { x = normalize_angle(representIntAsFloat(readMemory(11989576, 4, false))), z = normalize_angle(representIntAsFloat(readMemory(11989592, 4, false))) } local error_x, error_y = 0, 0 if state.firing.active then local progress = (current_time - state.firing.start_time) / CONFIG.animation.duration progress = math.min(progress, 1) local target_x = lerp(state.firing.start_pos.x, state.firing.target_pos.x, progress) local target_y = lerp(state.firing.start_pos.y, state.firing.target_pos.y, progress) error_x = target_x - state.cursor.x error_y = target_y - state.cursor.y if progress >= 1 then state.firing.active = false end else error_x = math.max(-state.cursor.x, -(delta_time * CONFIG.recoil.recovery_speed)) error_y = math.max(-state.cursor.y, -(delta_time * CONFIG.recoil.recovery_speed)) end state.cursor.x = state.cursor.x + error_x state.cursor.y = state.cursor.y + error_y setCameraPositionUnfixed(camera.x + error_x, camera.z + error_y)end
-- Utilities function normalize_angle(angle) return ((angle + math.pi) % (2 * math.pi)) - math.pi end
function lerp(start, finish, progress) return start + (finish - start) * progress end
- Assistant
Для того чтобы рассчитать
recovery_speed, чтобы время восстановления (в данном случае 400 мс) было верным, нам нужно понимать, как этот параметр влияет на перемещение курсора.Исходя из вашего кода:
- Длительность анимации: У вас есть переменная , которая равна , что соответствует .