I already setup a raycast from a point to the center of the camera, but my only problem is that its not on point.
The raycast goes below the center of the screen just by a bit. I am projecting a raycast from RightHand to CFrame.lookVector, see below
local origin = player.Character.RightHand.Position
local direction= workspace.CurrentCamera.CFrame.LookVector*50
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
Is there a way I can make it go on point without setting the origin to
local origin = CurrentCamera.CFrame.Position
I have searched everywhere for this solution, I will appreciate some feedback.
Thats what im trying to avoid, its because i want the projectile to spawn where the hand is and fly towards the center of the screen. However, If i set the origin to Camera.CFrame.Position, it will just spawn where the camera’s position is.
Yes, sorry. By raycasting from the screen you will get a target position (Vector3). Raycasting in the direction targetPosition - Hand.Position you will have a raycast from the hand to the point the camera is looking at
I think the problem might be that the ray hit something on its way to the center of the camera. My “not very smart” solution is to cast a ray from the camera directly forwards to get the true “center of camera” and then let the ray go for the “true center of camera”. If u find this confusing I can write an example code for u :).
local cameraraycastthatisforreferencelol = workspace:Raycast(workspace.Currentworkspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector*500)
local funnythingthatdemonstratestherealcameracenterpoint = cameraraycastthatisforreferencelol.Position
--your actual cast here lol
local origin = player.Character.RightHand.Position
local direction= funnythingthatdemonstratestherealcameracenterpoint
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
also I offer you an alternative solution if u are using shift lock switch (only works on local script):
local mouse = player:getmouse()
local origin = player.Character.RightHand.Position
local direction= mouse.hit
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
Okay so I understood where you came from and came with a solution.
I fired 2 raycasts, one from Origin of the Camera to the direction of the Camera lookVector. I took the true position and just made a unit from true position to the right hand.