Currently, I have a custom camera system that is reminiscent of a RTS (Real-Time Strategy) game’s camera: a top-down camera. I have overridden the default camera and control scripts (since I remove the character from the actual game). This works great, in fact, I really enjoy using the camera. I am however, having trouble porting the camera to be mobile-compatible.
The camera system can be seen here:
Camera Testing.rbxl (13.7 KB)
(Controls: WASD to move; scroll wheel to zoom in and out)
I have tried using UserInputService to accomplish this, but I’m not sure which event would be suitable. I’ve tried TouchSwipe, however the directions are rather limited (being only up,left,down,right - I need movement in diagonals as well). I then tried TouchPan, but wasn’t sure quite how to translate the Vector2 to a usable Vector3 within the game.
What I had tried was:
local uis = game:GetService("UserInputService")
uis.TouchSwipe:Connect(function(direction)
if direction == Enum.SwipeDirection.Right then
-- move right --
-- you get the idea --
end
end)
-- this however, didn't allow me to move in diagonal directions --
-- thus, I tried:
uis.TouchPan:Connect(function(touchPositions, translation, velocity)
move_vector = move_vector + Vector3.new(translation.X, 0, translation.Y)
end)
-- but this resulted in the camera just flying about whenever I swiped on screen
Neither of these solutions worked well at all. Any help would be appreciated
Edit:
After some fiddling, I resulted in:
uis.TouchPan:Connect(function(touchPositions, translation, velocity, state, processed)
if processed then return end
local vector = Vector3.new()
if translation.X > 0 then
vector = vector + Vector3.new(1,0,0)
else
vector = vector - Vector3.new(1,0,0)
end
if translation.Y > 0 then
vector = vector + Vector3.new(0,0,0.25)
else
vector = vector - Vector3.new(0,0,0.25)
end
move_vector = move_vector + vector
end)
This did solve the problem of the massive camera leaps, but the movement still doesn’t seem accurate. It seems whenever I swipe an a direction, it seems to move the camera at an odd angle, though it does seem fixable with some code edits.
Edit 2:
Finally, I ended up just doing this:
uip.TouchPan:Connect(function(touchPositions, translation, velocity, state, processed)
if processed then return end
local vector = Vector3.new(-translation.Y, 0, translation.X)
move_vector = (vector)*0.01
end)
This worked perfectly, and was much simpler lol.