I need help with a complicated mouse position system

Hey devs!
I’ve been working on a game for a little while that is inspired from a a mobile game in which you connect different orbs to make different combos and such. The camera locks in to a specific spot in a given plot, (I’ll provide pictures), but I want the player to be able to move the mouse back and forth over a specific range to see a preview of where the orb will drop.

However, I really don’t know how I would go about doing this. I considered using GetMouse and then just seeing if the mouse is in a certain X range given what plot the player has chosen, but then I realized my plots are lined on the Z axes. Problem is, given a mouse’ 2-D nature, it doesn’t have that.

I don’t think if I changed them to line the X that it would fix the issue, but correct me if im wrong.

I want the player to preview ehre they will drop their orb (number) before they click and drop it.

I’m just not really sure how to go about this.

3 Likes

If I’m understanding you correctly, what you need is to check the target of the mouse.

This will be the object in 3D space the mouse is pointing to.

Here’s how you could implement it into your script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

--Reference both parts in the workspace
local plot 
local orb

local function ShowOrbPath()
	--Checking if mouse is over the plot
	if mouse.Target == plot then
		--Draw orb path
	else
		--Hide orb path
	end
end
	
mouse.Move:Connect(ShowOrbPath)
1 Like

This sounds great I’ll try it on my PC then mark you if it works, but just to confirm, this spot property yields a Vector3, right?

You’ll also want to use mouse.Hit. It’ll return a CFrame, so make sure to use mouse.Hit.Position for the vector3.

If the plot is aligned with the grid, it should be as easy as setting orb’s x position.

Use this in combination with mouse.Target to move the orb only when the cursor is over the plot.