Projectile not acting as intended (tweening)

Basically, Im trying to get a part to fly to my cursor’s position, while being able to manipulate speed.

I’m using tweenservice, so my mouse cursor’s position is point B and my arm is point A. The issue is that tweening makes the part reach point B in the allotted time no matter the costs, so if i point my cursor at the sky, the part flies away at mach 15. I want to be able to manipulate the speed of the part, too.
ezgif.com-gif-maker

This entire ordeal originally used LinearVelocity and stuff, but that was incredibly difficult, and there was no way to control its “point B”, as it would just fly in one direction and my mouse.hit had nothing to do with it. tweening seemed like the best option, but as you’ve read, it doesnt align with my goals.

-- local Player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local model = game.Workspace.Noooooo
local endpoint = model.endof
local startpoint = Player.Character["Right Arm"]
local thing = model.best
local Mouse = Player:GetMouse()

while true do
	thing.Position = startpoint.Position
	TweenService:Create(thing,TweenInfo.new(5,Enum.EasingStyle.Linear),{Position = Mouse.hit.Position}):Play()
	wait (2)
end

im new here, so let me know if I’ve gotten some stuff wrong.

The time depends on what you enter as the first argument in TweenInfo. You can adjust it accordingly with time = distance/velocity.
Instead of entering a fixed time of 5 seconds, do something similar to this:

local dInitial = startpoint.Position.Magnitude -- initial distance
local dFinal = Mouse.hit.Position.Magnitude -- final distance
local dDelta = math.abs(dFinal-dInitial) -- the distance between the two points that the part will travel
local speed = 3 -- may have to change depending on the speed you want
local t = dDelta/speed -- time
TweenService:Create(thing,TweenInfo.new(t,Enum.EasingStyle.Linear),{Position = Mouse.hit.Position}):Play()
1 Like

That is because TweenService will move the part to the indicated point within the specified time (the first argument to TweenInfo.new) so you will need to calculate the velocity to put as speed parameter relatively to the distance