How can i make the fireball move to the mouse position when i hit click. As you can see the video below:
If I got you right, you can do this
First you create linear velocity and apply it to the fireball, than you set the velocity like this
LinearVelocity.VectorVelocity = CFrame.lookAt(player.Character.PrimaryPart.Position,Hit.Position).LookVector * speed
(please format your code instead of sending an image).
I would recommend using Camera:ScreenPointToRay
.
local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
local cam = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = true
params.RespectCanCollide = true
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
--then, when you need to:
local location = uis:GetMouseLocation()
local ray = cam:ScreenPointToRay(location.X, location.Y)
local hit = workspace:Raycast(ray.Origin, ray.Direction * 50, params)
if hit then
local tween = ts:Create(fireball, info, {CFrame = CFrame.new(hit.Position)})
tween:Play()
tween.Completed:Wait()
tween:Destroy()
end