Hello! I am making a shooting game. On pc if you click on your screen something will shoot towards your mouse position. But on mobile i must use a button to fire it. But the bullet will fire towards the button instead of the middle because the mouse is on the button of course. I’ve tried to make it mouse locked but it doesn’t work. I also read this post but idk how to convert that into the middle of the screen.
Summarize: I want to know the CFrame of the world that the middle of a user’s screen is pointing at. THanks!!!
workspace.CurrentCamera.CFrame.LookVector will get you the lookvector
are you trying to get the part the player is looking at or the position the player is looking at?
A more complicated way is to get the camera screen size, get the middle by multiplying by 0.5 then using camera:ScreenPointToRay then use Ray.Origin. It’s the same which is pretty interesting.
local camera = workspace.CurrentCamera
local screenSize = camera.ViewportSize
local screenRay = camera:ScreenPointToRay(screenSize.X*0.5, screenSize.Y*0.5)
print(screenRay.Origin) --Both similar
--Or simply just
print(camera.CFrame.Position)