Edit: After some looking around, I've realized that if I want to get the result I'm looking for, I'm gonna have to change the weapons themselves, rather than a single script. What I think I need to know now is how to get the position the camera is looking at so I can get the ranged weapons to fire there. Perhaps I could get it with raycasting?
I'm working on a game with plenty of ranged weapons, and I want to make them easier to use on mobile. I've started work on a script that makes an attack button appear whenever you equip a weapon on mobile. It works as it's supposed to... Kinda. It does activate the weapon whenever you tap the button, but it makes ranged weapons fire towards where you tapped, which, of course, is on the button, which is in the corner of the screen. I'd like to know how to make it so tapping the attack button makes ranged weapons fire in the direction the camera is facing, rather than towards the corner of the screen where the button is.
Here's my code:
local player = game.Players.LocalPlayer local character = player.Character if not character or not character.Parent then character = player.CharacterAdded:wait() end local uis = game:GetService("UserInputService") local ces = game:GetService("ContextActionService") --[[if uis.TouchEnabled then game:GetService("RunService").RenderStepped:Connect(function() uis.MouseBehavior = Enum.MouseBehavior.LockCenter uis.MouseIconEnabled = true end) end]]-- a failed attempt at making it work right local function activateweapon() if character:FindFirstChildOfClass("Tool") then character:FindFirstChildOfClass("Tool"):Activate() end end character.ChildAdded:Connect(function(child) if child:IsA("Tool") then child.ManualActivationOnly = true ces:BindAction("Attack", activateweapon, true) ces:SetTitle("Attack", "Attack") end end) character.ChildRemoving:Connect(function(child) if child:IsA("Tool") then child.ManualActivationOnly = false ces:UnbindAction("Attack") end end)
Please help me out here, I want to make mobile gameplay not terrible!