I’m trying to make the shoot button move where the player’s finger is touching it but it has a seizure when i use my other finger to move, switching back and forth between the 2 positions
the while loop is where it changes the position of the button
I’m trying to make the shoot button move where the player’s finger is touching it but it has a seizure when i use my other finger to move, switching back and forth between the 2 positions
the while loop is where it changes the position of the button
Can you provide us with a video of the bug or issue you are facing?
thats a bad way to do it, give half of the screen to moving around
why are you creating closure inside already separate thread?
Also you are implementing it pretty badly; You should make it event based.
What do you mean giving it half of the screen?
I don’t know which events to use, I’ve tried with TouchDrag, TouchPan and TouchMoved but they all still make it tweak out
Your 20% (or whatever you want it to be) of the left screen should be reserved for moving around, meaning check x position of input X so its in shoot area
The best way to solve this, in my opinion, would be:
put checks on how quickly the shoot button can change position (calculate distance between current position and new position, multiply by delta time (time since last position update), and compare to any speed threshold you set)
ignore positions outside of a specified area of the device’s screen (if x or y is below or above a certain value, ignore or position to maximum x/y value to demonstrate a boundary)
Adjust your speed constant so that it doesn’t ignore quick finger movements, but ignores super glitchy cross-screen movements. If these solutions don’t work, just make the button hold still.
ok i have managed to implement the boundary system, but now I have to figure out how to find an ‘offset’ boundary for all devices
When testing on PC, the boundary is 750 pixels and to position the button, the script uses offset positions for the button, but on phone this boundary becomes very tiny and locks the button to the far right of the screen (basically almost outside the phone’s screen) instead of middle or 1/4 of the right side of the screen
Pixel constants are hard to work with, since you’d have to update this value across different screen sizes as you mention. It’d be better to grab the screen size and divide it to get a fraction that you need.
For example, if you need 25% of the screen for the shoot button, then you’d divide the total screen size by 4. You can grab the screen size via the absolute size value of a ScreenGui instance.
Sample code of determining a 25% boundary on the right side of the screen:
local playerGui = game.Players.LocalPlayer.PlayerGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
local boundary = screenGui.AbsoluteSize.X * 0.75
screenGui:Destroy()
while true do
if hold == false then return end
local currentPosition = UDim2.new(0, UIS:GetMouseLocation().X, 0, UIS:GetMouseLocation().Y - shootButton.AbsoluteSize.Y)
if currentPosition.X.Offset < boundary then
currentPosition = UDim2.new(0, boundary, 0, UIS:GetMouseLocation().Y)
end
shootButton.Position = currentPosition
task.wait()
end
When you use UserInputService.InputBegan, it has a parameter of the gameproccssed and the input. you can store the touch input outside of that function so that when another input gets proccssed, you just ignore that one. use InputEnded to check if the input from InputEnded is equal to the saved input and set the saved input to nil so that the next input gets processed
Okay after using every solution I decided to make the button with a textbutton that covers half the screen, and inside of it there’s the imagebutton with the shoot icon; basically removing the moving button
The shoot icon handles the player pressing it then when the player removes their finger, it stops the shooting as the textbutton handles the touch input stopping
since the shoot loop keeps going if the finger goes outside the textbutton/hitbox, I made it so that if the touch was stopped outside the hitbox, it’ll stop shooting; this one was done with UserInputService’s gameprocessed parameter
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.