How do I make mouse.Hit.p always be the center of my screen? (VERY URGENT)

My father is going to sell my PC soon lol, how do I do it here anyway?:

local Direction = (CFrame.new(Start,Mouse.Hit.p) * CFrame.Angles(math.rad(-Spread+(math.random()*(Spread*2))),math.rad(-Spread+(math.random()*(Spread*2))),0)).lookVector

I need that for support mobile in a first person shooter system.

3 Likes

Are you trying to raycast relative to the camera’s looking direction?

local direction = workspace.CurrentCamera.CFrame.LookVector

This should work fine for a first-person system.

4 Likes

It didnt work
(local Direction = (CFrame.new(workspace.CurrentCamera.CFrame.LookVector) * CFrame.Angles(math.rad(-Spread+(math.random()(Spread2))),math.rad(-Spread+(math.random()(Spread2))),0)).lookVector)

2 Likes

I think ScreenPointToRay is what you want, here’s some sample code on generating the ray (in which you can retrieve the direction)

local cam = workspace.CurrentCamera
local screenToWorldRay = cam:ScreenPointToRay(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
 
local rayResult = workspace:Raycast(screenToWorldRay.Origin, screenToWorldRay.Direction * LENGTH)

1 Like

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