I had wasted over 5 hours trying to apply Drag to FastCast physic with this formula and the two methods I made up, but to no avail. Here’s what these methods look like:
-Method 1: Modifying InitialVelocity inside FastCast module (ActiveCast)
-- Simulate a raycast by one tick.
local function SimulateCast(cast: ActiveCast, delta: number, expectingShortCall: boolean)
assert(cast.StateInfo.UpdateConnection ~= nil, ERR_OBJECT_DISPOSED)
PrintDebug("Casting for frame.")
local latestTrajectory = cast.StateInfo.Trajectories[#cast.StateInfo.Trajectories]
local origin = latestTrajectory.Origin
local totalDelta = cast.StateInfo.TotalRuntime - latestTrajectory.StartTime
--TEST
local drag = 2.5
latestTrajectory.InitialVelocity *= GetDragFactor(totalDelta, drag)
...
end
The result: projectiles’ velocities began to decay when firing, but at halfway, they gradually reversed to the origin (fire point), and their accelerations remained unaffected
-Method 2: Using FastCast API “:SetVelocity()” to modify Velocity (or InitialVelocity) with Drag
local function OnRayUpdated(Cast, LastSegmentOrigin, SegmentOrigin, SegmentDirection, Length, SegmentVelocity, CosmeticBulletObject)
local Drag = 2.5
if Drag > 0 then
--Using TotalRuntime2 as custom elapsed time because vanilla TotalRuntime usually reverses. Look inside ActiveCast module for detail
Cast:SetVelocity(SegmentVelocity * (2 ^ (Cast.StateInfo.TotalRuntime2 * Drag)))
end
end
Caster.LengthChanged:Connect(OnRayUpdated)
The result: same as method 1, except they didn’t travel back to their origins, but their accelerations were affected instead
(clip 1, no drag, bullet speed = 25, acceleration = Vector3.new(0, -20, 0))
(clip 1.2, same attributes, but drag = 2.5)
(clip 2, no drag, no bullet speed, acceleration = Vector3.new(0, -100, 0))
(clip 2.2, same attributes, but drag = 1)
It was strange when these two had opposite, yet failed results, although they only modified InitialVelocity and nothing else
If anyone knows the better way to implement it, please reply. Thank you
PS: you can use this model for testing