In my game an arrow part (Shooter) follows the mouse button while the mouse target is over a certain part (Set.Front). When you click the mouse, a ball at the arrow part fires in the direction the arrow part is pointed. Think Puzzle Bobble if you’re familiar. This all works perfectly on PC…
…but I’m not real familiar with the workings of mobile. My thought is I would like the arrow part only to move once the user is touching the screen and only after touching the Set.Front part, then to follow the pointer while dragging, then to fire the ball when releasing. I’m guessing this is some combination of TouchStarted, TouchMoved and TouchEnded functions, but my research has me wrapped around the axle a bit. Appreciate a nudge in the right direction.
Here is my current script – again, all PC function with the mouse is perfect. The Touch stuff is a mess. With this current iteration while on mobile the shooter does not move, though the ball does fire when the touch is released. I also have to work out the issue of the camera on mobile rotating while dragging, which should be stopped, at least temporarily, while dragging to move the shooter arrow.
Not working:
local function ShooterMovement(Set)
local Shooter = Set.Shooter
if UserInputService.TouchEnabled then
UserInputService.TouchMoved:Connect (function(Input)
--if Input.position == Set.Front then
local pos = Vector3.new(Shooter.Position.X, Input.Position.Y, Input.Position.Z)
Shooter.CFrame = CFrame.new(Shooter.Position, pos)
--end
end)
else
this part works fine:
Mouse.Move:Connect(function()
if Mouse.target == Set.Front then
local pos = Vector3.new(Shooter.Position.X, Mouse.Hit.Position.Y, Mouse.Hit.Position.Z)
Shooter.CFrame = CFrame.new(Shooter.Position, pos)
--game.ReplicatedStorage.RemoteEventShooterUpdate:FireServer(Set,Shooter.CFrame) --- UPDATE SHOOTER POS ON SERVER - TEMPORARILY DISABLED TO REDUCE LAG
end
end)
end
end
And for shooting, actually this first part does work to fire the ball, although the shooter is fixed, and again the mouse portion further down functions fine.
-------------------- SHOOT BALL -------------------------
local function Shoot(Set)
local MouseDB = false
if UserInputService.TouchEnabled then
UserInputService.TouchEnded:Connect(function()
Set.ActiveBall:ApplyImpulse(Set.Shooter.CFrame.LookVector * 80) --<<<<<<<<<< SHOOT THE BALL
Player.character.Head.Shoot:Play()
BallInPlay = true
end)
else
Mouse.Button1Down:Connect(function()
Set.ActiveBall:ApplyImpulse(Set.Shooter.CFrame.LookVector * 80) --<<<<<<<<<< SHOOT THE BALL
Player.character.Head.Shoot:Play()
BallInPlay = true
end)
end
end