Trouble in a 2D game, getting an accurate mouse position

I’m back again after a short period of time from my last post.
Making a 2d game is a bit difficult because there isn’t so much info or documentation when it comes to it.

Anyway I’ve been trying to do this for 3 days now. I want to make a fireball that would go where the player cursor is. Now I’ve been scripting for a while so this was relatively easy. Except for the cursor part. Every time I do this it turns out like this:
unknown

function abilities:NewFireball(plr, mlv)
	local newFireball = game.ReplicatedStorage.AbilityParts.Fireball:Clone()
	newFireball.CFrame = plr.Character.PrimaryPart.CFrame
	newFireball.Parent = workspace.Skills
	
	local connection
	connection = game:GetService("RunService").Heartbeat:Connect(function(dt)
		newFireball.CFrame = CFrame.new(newFireball.Position) + Vector3.new(mlv.X, mlv.Y*2, 0)
	end)
	
	task.delay(3, function()
		connection:Disconnect()
		newFireball:Destroy()
	end)
end

mlv = mouse.Hit.LookVector

I’m almost sure this happens due to the fact that there is no Z value. If I change it so that it goes on the Z axis as well, it goes off the map but I can kind of make out that it’s accurate. Anybody got a solution?

I haven’t really looked into this but you might want to look into ray casting as a possible solution.
https://create.roblox.com/docs/mechanics/raycasting

I have tried raycasting and there is no reason for me to use it as it requires the ray to hit something and I don’t want that.

Ok after some further help I discovered a solution that works and it involves CFrame.lookAt()

local connection
	connection = game:GetService("RunService").Heartbeat:Connect(function(dt)
		newFireball.CFrame = CFrame.new(newFireball.Position) + dir.LookVector * dt * 8
	end)
1 Like