teleport and lerp() are disqualified cus teleport is not travelling in a technical perspective(i am a spacial tracking fan) and lerp() is basically teleport if u think abt it. So far i find the best method is relating the distance between the start and end points of the projectile's course with its velocity; and the much more easy bodyposition. But are there any better ways?
To do this, I would use TweenService
. Get the CFrame
info of the target part, like this:
local TargetPos = {CFrame = workspace.Target.CFrame}
First make sure the target part and the projectile are both Anchored
. Then create the tween information for projectile like this.
local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Inout, 0, false, 0)
The above code creates the info for the Tween
, which says that the projectile will travel to the target in 0.5 seconds without any smoothing (easing). Also make sure you actually create and play the tween, from the server side.
local TService = game:GetService("TweenService") TService:Create(workspace.Projectile,tweeninfo,TargetPos)
Your final code should be:
local Target = {CFrame = workspace.Target.CFrame} local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Inout, 0, false, 0) local TService = game:GetService("TweenService") local tween = TService:Create(workspace.Projectile,tweeninfo,TargetPos) tween:Play()
There are other ways of tweening parts but this is usually how I do it. Hope this helped. If I got something wrong please leave a comment since I'm just writing this off the top of my head around midnight.