# Problem with Tweening Projectile to Mouse Position

I need to figure out how I can make it so tweening to mouse.position behaves like body velocity.

My issue is, basically if your mouse were to land on a player, if that player moved, it would still stop at that position where it hit the player. So if i’m throwing a projectile at a player’s head and they move, it’s gonna stop at where their head was.

I’ve tried looking up a solution on devforum but I couldn’t find anything, I even used google chrome.

There are a few ways to solve this.
LinearVelocity works like BodyVelocity, except its new.

AlignPosition will work as tween towards a part however it will slow down when it is approaching the target part.

Good suggestion but I would like to apply it to this script.

``````            local PointA = Limb.Position
local PointB 	= MouseHit.Position
local Dist		= (PointA - PointB).magnitude -- The distance between PointA and PointB

local TotalPoints 	= (Limb.Position - MouseHit.Position).Magnitude/30 	-- The number of of times you want the projectile to "zig-zag"
local MaxOffset		= 5	-- The max offset of each point in studs
local Duration		= 0.1	-- The duration of the interpolation between each point

local Info = TweenInfo.new(Duration, Enum.EasingStyle.Linear)

for i = 1, TotalPoints do

-- First get the point on the linear path
local pointCF = CFrame.new(PointA,PointB) * CFrame.new(0, 0, -Dist * (i / (TotalPoints + 1)))

-- Calculate the offset of the point from the path
local offset = CFrame.new(math.random() * MaxOffset, math.random() * MaxOffset, 0)

-- Apply the offset to the point cframe
local finalPointCF = pointCF * offset

-- Move the part towards the final point cframe
local tween = TweenService:Create(NewBall, TweenInfo.new(Duration,Enum.EasingStyle.Linear), {CFrame = finalPointCF})
tween:Play()

wait(Duration)
end

local tween = TweenService:Create(NewBall, TweenInfo.new(Duration,Enum.EasingStyle.Linear), {CFrame = CFrame.new(PointB)})
tween:Play()
``````

Tweening the position may work, I’m not quite sure what your goal is.

TweenService is very powerful, but it isn’t always the solution. When it comes to projectiles I’d use LinearVelocity (roblox.com), at least if they are going straight forward. `LinearVelocity` is `BodyVelocity`'s replacement. It has plenty of features I have not yet experimented with, however from the little experimentation I have done I think this might be a good place to start looking.

If you wondered how you applied a linear velocity then this is how:

``````local vel = Instance.new("LinearVelocity")
... -- Configure different properties, such as VelocityConstraintMode
vel.Parent = newBall
``````
1 Like

I will try to use it in future projects, although this isn’t a solution to my problem I have been trying to find a replacement for body velocity since it’s deprecated, thank you so much!

LinearVelocity can do everything BodyVelocity can do, I would recommend using this or another similar approach.

Sorry I was unable to solve your issue, best of luck!

1 Like

Thank you so much, big help!!!