Hello. I am working on a system for my mobile players, where this rock thrown aims toward the center of the screen, to supplement for not having a mouse. It works, mostly. However, I have ran into an issue. Whenever the player aims high or low enough, the rock shoots backwards. I am using fastcast.
This is my code for calculating the position of the center of the screen. For the aiming itself, I stole a snippet of code from MouseModule - Roblox (The module’s .Hit and .Raycast function.), and made it work with my center aiming system.
local center = workspace.CurrentCamera.ViewportSize / 2
local viewportRay = workspace.CurrentCamera:ViewportPointToRay(center.X, center.Y)
local result = workspace:Raycast(viewportRay.Origin, viewportRay.Direction * 1000)
local MAX = 1e4-2
local crosshair = (result and CFrame.lookAt(result.Position, result.Position+viewportRay.Direction) or CFrame.lookAt(viewportRay.Origin+viewportRay.Direction*MAX, viewportRay.Origin+viewportRay.Direction*(MAX+1)))
fireEvent:FireServer(crosshair.Position)
Please excuse the bad quality of the video, I was using the device replicator and roblox’s built in screen recorder.
robloxapp-20220221-1055204.wmv (2.8 MB)