Hi everyone! I was working on a game and I wanted to make an interaction system. There’s no issue for PC players but there’s a problem for Mobile players. As you see in the video, visuality not works how I want. For the Mobile/Console players, I’m getting the middle of the screen to check the distance between the interaction item and Mouse/Target/Point.
if Player:GetAttribute("Device") == "Mobile" or Player:GetAttribute("Device") == "Console" then
local VectorPoint = Vector2.new(InteractionUI.AbsoluteSize.X/2, InteractionUI.AbsoluteSize.Y/2) --to get middle of the screen
local ray = Camera:ViewportPointToRay(VectorPoint.X, VectorPoint.Y, 0) --raycasting
local raycastResult = workspace:Raycast(
ray.Origin,
(ray.Direction)*Settings.RenderRange,
raycastParams
)
if raycastResult then
MouseDistance = (PrimaryPart.Position - raycastResult.Position).Magnitude
else
MouseDistance = 9999
end
else
MouseDistance = (PrimaryPart.Position - Mouse.Hit.Position).Magnitude
end