I was testing out some mobile input stuff like .TouchStarted and .TouchMoved and while using it I was getting some confusing values. My goal was to get the screen point of the touch into a UDim2.
Video showing issue: (wouldn’t let me upload to post)
video
The UI frames position is the Camera:WorldToScreenPoint function giving the touch’s position in the parameters but converted into a UDim2, if I am doing that correctly.
The Red part’s position is what I get from a Camera:WorldToScreenPoint function giving the touch’s position in the parameters.
The Blue part’s position is the .Position of the touch returned by the event.
local input = game:GetService("UserInputService")
local frame = script.Parent.Frame
input.TouchStarted:Connect(function(touch, gameEvent)
print("started")
print(tostring(touch))
print(touch.Position)
local newpos = workspace.CurrentCamera:WorldToScreenPoint(touch.Position)
--print(tostring(touchInfo[name].Position) .. "|" .. tostring(touch.Position))
print(tostring(Vector2.new(newpos.X, newpos.Y)))
frame.Position = UDim2.new(0, newpos.X, 0, newpos.Y)
local newpart = Instance.new("Part")
newpart.Parent = workspace
newpart.Anchored = true
newpart.Material = Enum.Material.Neon
newpart.BrickColor = BrickColor.Red()
newpart.Position = touch.Position
local newpart2 = Instance.new("Part")
newpart2.Parent = workspace
newpart2.Anchored = true
newpart2.Material = Enum.Material.Neon
newpart2.BrickColor = BrickColor.Blue()
newpart2.Position = newpos
end)
input.TouchMoved:Connect(function(touch, gameEvent)
print("moved")
print(tostring(touch))
print(touch.Position)
local newpos = workspace.CurrentCamera:WorldToScreenPoint(touch.Position)
print(tostring(Vector2.new(newpos.X, newpos.Y)))
frame.Position = UDim2.new(0, newpos.X, 0, newpos.Y)
end)
input.TouchEnded:Connect(function(touch, gameEvent)
print("ended")
print(tostring(touch))
print(touch.Position)
end)
If someone could explain what these values are that I am getting, or how to convert them into a UDim2, that’d be very helpful!