TouchEnded function has inaccurate touch position

Hello! I’m currently making a system which applies impulse on an object using the swipe of your finger. I’ve used both the TouchStarted and TouchEnded to do this for mobile. I had planned that with the touch parameter in the TouchEnded function, I could get its position to create a lookvector for the object to push it towards the location of where you released your finger. This mostly works, except the position of the touch isn’t anywhere near where it should be. Anybody know how I could fix this?

UserInputService.TouchEnded:Connect(function(touch, gpe)
	if push then
		push = false
		Part.BrickColor = BrickColor.new("Really black")
		game.ReplicatedStorage.RemoteEvent:FireServer(touch.Position, Part)
		print(touch.Position) -- Output is both the X and Y being in the void, and Z always being 0
		camera.CameraType = Enum.CameraType.Custom
	end
end)

I figured out that I just needed to copy the raycasting I did in the TouchStarted function to get the point of intersection and send the object there.

local unitRay = camera:ScreenPointToRay(touch.Position.X, touch.Position.Y)
		local direc = unitRay.Direction
		local dis = 50
		local filter = {workspace.InvisBarriers:GetChildren()}
		local raycastparams = RaycastParams.new()
		raycastparams.FilterType = Enum.RaycastFilterType.Exclude
		raycastparams.FilterDescendantsInstances = filter
		local foundobj = workspace:Raycast(unitRay.Origin, direc * dis, raycastparams)
		game.ReplicatedStorage.RemoteEvent:FireServer(foundobj.Position, Part)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.