I am working on updating my module Placement Service which is a module for sandbox tycoon placement. In the past I have not implemented cross platform abilities but today I decided to give it a go. My only issue is that when on mobile, when I click the mobile button to rotate, raise, lower the model, it comes to that mouse location. Does anyone know how to prevent this or if it’s even possible? I will need a button for placement and the problem is that it will move position when the player tries to place an object. I tried not using buttons as well, but this resulted in an object being placed everytime the user moved the camera.
Here is what I mean:
Here is my code for adding mobile buttons:
-- rotate/terminate/raise/lowerLocation are just UDim2 values that can be set by the user.
local function updateButtons()
contextActionService:SetPosition("Rotate", rotateLocation)
contextActionService:SetTitle("Rotate", "Rotate")
contextActionService:SetPosition("Terminate", terminateLocation)
contextActionService:SetTitle("Terminate", "Cancel")
if enableFloors then
contextActionService:SetPosition("Raise", raiseLocation)
contextActionService:SetTitle("Raise", "Raise")
contextActionService:SetPosition("Lower", lowerLocation)
contextActionService:SetTitle("Lower", "Lower")
end
end
local function bindInputs()
contextActionService:BindAction("Rotate", rotate, true, rotateKey, xboxRotate)
contextActionService:BindAction("Terminate", TERMINATE_PLACEMENT, true, terminateKey, xboxTerminate)
if enableFloors then
contextActionService:BindAction("Raise", raiseFloor, true, raiseKey, xboxRaise)
contextActionService:BindAction("Lower", lowerFloor, true, lowerKey, xboxLower)
end
updateButtons()
end
I didn’t include the code for the actual rotate/terminate/raise/lower functions themselves as they have not changed from the published module and have no affect on this.
So just to re-iterate when someone goes and clicks on the actual button to rotate / or change the vertical placement of the object it just puts the instance that you are moving around with your mouse that you want rotated or raised / lowered in that position instead and not actually doing the button clicking?
No it does the clicking, the problem is that the model instantly moves to the mouse position which I dont (especially when placing objects) want when interacting with the buttons. I dont really know if this is even possible though which is why I created the post.
Ah I see so it’s not ignoring the user input despite the player still clicking the button.
If this is what I am guessing is happening I recommend first putting the active property the frames that are parented to the buttons. This should ignore the user input outside of the buttons themselves.
Hold on, what if you checked where they clicked and ignored the input if their cursor touched within the frame. So if their cursor is touching within the frame ignore the input on the 3d placement side.
Yes, just disconnect any of the connections or have a boolean governing over them so if that boolean is false don’t do anything with the input, or if you just disconnect / reconnect it.
Since I’m using context action service, I cannot seem to get a signal from the buttons that detects when the mouse enters the button. It worked with normal UI elements that I manually create, however that wouldn’t work as it seems impossible to get a reliable way to only display UI to mobile.
Fixed by using raycasts. Shot a ray from the center of the screen and used that as the mouse coord instead of the actual mouse. This way, only when the screen changes position the object moves instead of when the mouse moves (which includes when you press UI buttons).
local cam = workspace.CurrentCamera
local camPos = cam.CFrame.Position
local ray = workspace:Raycast(camPos, cam.CFrame.LookVector*maxRange, raycastParams)
Anyway that’s how I solved it if anyone is wondering.