Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

what is the best way to make a projectile always travel to any location in a fixed amount of time?

Asked by 6 years ago
Edited 6 years ago

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?

0
lol TheluaBanana 946 — 6y

1 answer

Log in to vote
0
Answered by
CodyDev 70
6 years ago

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.

0
oof. Well im sorry to have wasted ur time but tweenservice is also just segmented teleporting, like lerp(). Its late in night, i dont blame u, but if u did read the guidelines i did mention anything related to teleporting would not be counted as i want the projectile to completely cover its course, if u know what i mean. TheluaBanana 946 — 6y
0
but thanks for trying TheluaBanana 946 — 6y
0
It's fine, don't worry about it. CodyDev 70 — 6y
Ad

Answer this question