I’m creating a soft tracking system for slow projectiles using VectorForces. Everything works as intended so far, but I can’t figure out how to make the projectile travel at a constant velocity.
https://gyazo.com/1c8f6020204bd42d535584979b47edc6
How would I add a velocity cap to this VectorForce? The direction it needs to travel in is constantly updated by rotating the part. As you can see in this gif, the part continues getting faster and faster.
Any help is appreciated.
Create_ServerCopy_Event.OnServerEvent:connect(function(plr, LockedTarget, mousehit)
local plr_GodPowers = Server_Runtime_GodPowers:WaitForChild(plr.Name)
local Body_Parts = Universal_Checks.Get_Body_Parts(plr)
local Cloned_Jutsu = Fire_GodPowers:WaitForChild("Server_BlazingFireball"):Clone()
local pos = Body_Parts["RootPart"].Position + Vector3.new(0, 2.5, 0)
Cloned_Jutsu.CFrame = Body_Parts["RootPart"].CFrame * CFrame.new(0, 2.5, 0)
Cloned_Jutsu.CFrame = Cloned_Jutsu.CFrame + Cloned_Jutsu.CFrame.lookVector * 3
Cloned_Jutsu.Parent = plr_GodPowers
Cloned_Jutsu:SetNetworkOwner(nil)
local VectorForce = Cloned_Jutsu:WaitForChild("VectorForce")
RunService.Heartbeat:connect(function()
local StartCFrame = Cloned_Jutsu.CFrame
local startX, startY, startZ = StartCFrame:ToOrientation()
local jutsuPos = Cloned_Jutsu.Position
local target
if LockedTarget then
target = game.Players:WaitForChild(LockedTarget).Character:WaitForChild("UpperTorso").Position
else
target = mousehit
end
local DesiredCFrame = CFrame.new(jutsuPos, target)
local desiredX, desiredY, desiredZ = DesiredCFrame:ToOrientation()
local DifferenceX = find_Difference(startX, desiredX)
local DifferenceY = find_Difference(startY, desiredY)
local DifferenceZ = find_Difference(startZ, desiredZ)
local RotatedX = find_Rotation(startX, desiredX, DifferenceX)
local RotatedY = find_Rotation(startY, desiredY, DifferenceY)
local RotatedZ = find_Rotation(startZ, desiredZ, DifferenceZ)
if RotatedX ~= 0 or RotatedY ~= 0 or RotatedZ ~= 0 then
Cloned_Jutsu.CFrame = Cloned_Jutsu.CFrame * CFrame.Angles(RotatedX, RotatedY, RotatedZ)
local LookVector = Cloned_Jutsu.CFrame.lookVector
VectorForce.Force = Vector3.new(LookVector.X, LookVector.Y, LookVector.Z) * (10000)
VectorForce.Force = VectorForce.Force + Vector3.new(0, workspace.Gravity * Cloned_Jutsu:GetMass(), 0)
end
end)
end)