You can write your topic however you want, but you need to answer these questions:
I am trying to make a projectile using the Tween Service. It works but when I attempt to fire the projectiles towards the sky they don’t go at the speed they’re supposed to go and really slow down
Firing towards ground
Firing towards sky
The code for the projectile tweening
local Pos = mouse.Hit.p
local TI = TweenInfo.new(
(Star.Position - Pos).Magnitude * 0.5 / 50,
Enum.EasingStyle.Cubic,
Enum.EasingDirection.In
)
TS:Create(Star,TI,{CFrame = CFrame.new(Pos)}):Play()
If you’re aiming towards the sky. mouse.Hit will be thousands of studs away, but if you’re aiming towards the ground, mouse.Hit will be much closer. The reason the effect isn’t showing while you’re firing towards the sky is because the distance is too large.
If you want to mitigate this, the easiest solution would be to add a maximum distance (so that if you’re firing at the sky, it ends somewhere).
Let’s say that the .Magnitude is 8,000. 8,000 * 0.5 / 50 (80 studs!) is still incredibly large for your purpose. You’ll need to add an “if” statement with a maximum distance.
No worries. It’s a pretty simple fix. I set the maxTime to 10, but if you want to change it higher or lower, just change the variable to fit your needs.
local Pos = mouse.Hit.p;
local time;
local maxTime = 10;
if ((Star.Position - Pos).Magnitude * 0.5 / 50 > maxTime) then
time = maxTime;
else
time = (Star.Position - Pos).Magnitude * 0.5 / 50;
end
local TI = TweenInfo.new(
time,
Enum.EasingStyle.Cubic,
Enum.EasingDirection.In
)
TS:Create(Star,TI,{CFrame = CFrame.new(Pos)}):Play();
It worked thank you so much.
Also style as in ability effects? those are something I’ve been doing for a while now so I decided I wanted to actually attempt to make something with them
Let’s say that you want the projectile to move 1 stud per second. If the target is 9 studs away, you’ll multiply that to get 9 seconds and keep the same ratio of time to distance. If that doesn’t work, try messing with the maxTime variable and seeing if that fixes anything.
that helped but didn’t completely fix it, but changing the easing from in to linear did completely fix it.
Kind of a shame I think the easing style added a nice touch to the effect
Use ‘Out’ for the easing direction, additionally, as suggested here.
The time should be clamped between two values, such that it isn’t too small nor too large.
local Enumeration = Enum
local Game = game
local TweenService = Game:GetService("TweenService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Star --Define this.
local Distance = (Mouse.Hit.Position - Star.Position).Magnitude
local Time = math.clamp(Distance / 100, 2, 10) --Use a clamping function to clamp the result between two values.
local Tween = TweenService:Create(Star, TweenInfo.new(Time, Enumeration.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = CFrame.new(Mouse.Hit.Position)})
Tween:Play()
I’ve clamped the value between two and ten although you may need to fiddle with those values until you reach the desired result.