--!native --!optimize 2 -- Compiled with roblox-ts v3.0.0 local TS = _G[script] local Workspace = TS.import(script, TS.getModule(script, "@rbxts", "services")).Workspace local PhysicsTools = {} do local _container = PhysicsTools --[[ *WIP * calculates the vertical velocity for parabolic trajectory with horizontal speed * @param horizontal_speed horizontal speed * @param offset distance from launcher to target; (target.Position - launcher.Position); ]] local function CalculateTrajectoryVerticalVelocity(horizontal_speed, offset) local _offset = offset local _vector3 = Vector3.new(1, 0, 1) local horizontal_offset = _offset * _vector3 local horizontal_distance = horizontal_offset.Magnitude --should be negative or positive local vertical_distance = offset.Y local vertical_speed = (vertical_distance * horizontal_speed + ((Workspace.Gravity / 2) * horizontal_distance * horizontal_distance) / horizontal_speed) / horizontal_distance return vertical_speed end _container.CalculateTrajectoryVerticalVelocity = CalculateTrajectoryVerticalVelocity --[[ * * @param point * @param start start of the line * @param finish end of the line * @returns [t, position, is_on_the_line] ]] local function GetClosestPositionOnLine(point, start, finish) local _finish = finish local _start = start local line_offset = _finish - _start local _point = point local _start_1 = start local offset = _point - _start_1 local t = offset:Dot(line_offset) / line_offset:Dot(line_offset) local position_of_line_offset = line_offset * t local position_on_line = start + position_of_line_offset return t, position_on_line, t >= 0 and t <= 1 end _container.GetClosestPositionOnLine = GetClosestPositionOnLine end return { PhysicsTools = PhysicsTools, }