Hi, I am trying to make a ability where you click, and then a fireball goes where the mouse is. I have something done with it, but all it does is teleport to the position. Is there a way to make the part to go smoothly to the mouse?
tool.Activated:Connect(function()
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
part.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(0,0,-10), mouse.Hit.Position)
wait(.005)
part.CFrame = CFrame.new(mouse.Hit.p)
mouse.TargetFilter = part and part2
end)
2 Likes
You can use Tweening or Lerping to slowly change CFrame or positions over time;
TweenService
Lerping(devforum)
Yes, i do know how to tween, but when i tried tween it said unable to cast to dictionary.
What was your code when you tried to tween it?
local tween = Tweenservice:Create(part, tweenInfo, part.Position = mouse.Hit.p)
tween:Play()
I think the third parameter requires a table, not sure though
You have to make a table like this:
local tween = Tweenservice:Create(part, tweenInfo, {Position = mouse.Hit.p})
tween:Play()
1 Like
I tried it, but it still said unable to cast to dictionary.
You could potentially use a RocketPropulsion to achieve this. And it’s arguably better than just tweening / lerping because of the unique properties which can be used for maximum results.
Also, the p
property of Mouse.Hit
is deprecated. use Position
instead. (Mouse.Hit.Position
)
Now the part you want to move is named “Part” and you have a Table called “TweenInfo” that holds the information for the tween.
Part is the part I want to move, TweenInfo holds the time, easing style, and the last part is the position
Can I see your entire script with the Tween. When it says “unable to cast dictionary”, there was a problem with one of the three parameters.
Im trying RocketPropulsion just one sec
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear)
local tween = tweenService:Create(part, tweenInfo, {part.Position == mouse.Hit.Position})
tween:Play()
For the final parameter, you don’t say part.Position. Instead you want just so say Position. Also these “==” are for comparing, you want this “=” for setting the Position. Overall it looks like this:
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear)
local tween = tweenService:Create(part, tweenInfo, {Position = mouse.Hit.Position})
tween:Play()
Ok nvm lol i didnt read the whole thing
1 Like
You need to use 1 =, not 2.
== is for comparing
{Position = mouse.Hit.Position}
Thanks! it works now! it dont know what to say
1 Like