What do you want to achieve?
Whenever I click anywhere in the Map Background UI, I want to fire the remote event with Mouse Position in it, so then, the CFrame Value will be the exact same position but in 3D, while doing that, this Red Dot will move there.
(Before you ask, yes, I’m aware that there is Vector3 Value, but, I would like to use this one for some reasons.)
What is the issue?
However, there is ONE PROBLEM THAT I COULDN’T FIX, and, that is, whenever I tried to click below it, it moves down, that looks okay, yeah? But, If I click above it, it just gets slow and it’s not even moving up, you will see what I meant. https://gyazo.com/2fe9c7bdb97b76fc6a10b56c7c5a891d
What solutions have you tried so far?
I tried to find any solutions about this, but, there doesn’t seem to be what I’m looking for, and, I’m stuck here trying to figure out how to fix this. So, please, if you have a solution for me, I would appreciate it!
Once you have the pixel location of the mouse, a useful method is given by the camera instance to convert that into a ray in 3D. Here’s the docs Camera:ViewportPointToRay
I’ve actually encountered something very similar to you and all I have to say is you need a couple hacky methods in order to do this successfully.
First off you need a part the size of the entire map. For now lets refer to this part as MapScale. It doesn’t have to be visible or interfere with game play at all. just turn off collisions and cantouch. I conveniently have this function already made as I said I’ve done this myself:
local function relative_pos(X,Y,Gui_Object)
local newAirstrikeIcon = airStrikeIcon:Clone()
local absoluteSize = Gui_Object.AbsoluteSize
local absolutePosition = Gui_Object.AbsolutePosition
local midPointX = (absoluteSize.X/2)+absolutePosition.X
local midPointY = (absoluteSize.Y/2)+absolutePosition.Y
local preXCoord = -X + midPointX
local preYCoord = -Y + midPointY
local xCoord = preXCoord/absoluteSize.X
local yCoord = preYCoord/absoluteSize.Y
newAirstrikeIcon.Position = UDim2.new(0,X-absolutePosition.X,0,Y-absolutePosition.Y)
newAirstrikeIcon.Parent = Gui_Object
placeAttachment:FireServer(xCoord,yCoord)
end
This should be in the local script. What this function does is take the size of the map gui and converts the mouses X and Y coordinates to a point on MapScale. Then fires an event to the server. Once you’re on the server script this line of code with get the exact position on part
local coordConversion = Vector3.new(coordX*baseplate.Size.X,0,baseplate.Size.Z*coordY)
That’s what I had to do to solve it for myself. I originally wasn’t going to share this but I didn’t want you to go through the same multi day ordeal as I did.
Of course, this is the code I have so far, could you figure out what’s wrong with this? I’m not familiar with this 2D stuff, to be honest
-- // Server Script // --
local function Move(Player, CFrame_Value, Mouse_Position)
if CFrame_Value then
local Speed = CFrame_Value:FindFirstChild("Speed")
if Speed then
local Vector = Vector3.new(Mouse_Position.Y, 0, 0) -- // For testing purposes
local Distance = (CFrame_Value.Value.Position - Vector).Magnitude -- // Tween Speed
TweenService:Create(
CFrame_Value,
TweenInfo.new(
Distance / Speed.Value,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
),
{Value = CFrame.new(Vector)}
):Play()
end
end
end
Move_Event.OnServerEvent:Connect(Move)
-- // Client Script // --
Map_Background.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
if Selected_Dot then
local Position = UserInputService:GetMouseLocation()
Move_Event:FireServer(Selected_Dot, Position)
print(Mouse_Position)
end
end
end)
I think that has something to do with it needing to be converted to the objectspace if I’m not mistaken. I’m not 100% sure since when I did it I just put ScalePart at 0,0,0