As of now, I’m trying to find the best way to get the direction I need to fire in for a third person gun.
When I fire, I pass over to the server a ViewportPointToRay returned ray:
CurrentCamera:ViewportPointToRay(CurrentCamera.ViewportSize.X/2, CurrentCamera.ViewportSize.Y/2)
(This is essentially the middle of the screen)
Then on the server, I do some calculations:
local ScreenPosition = (ScreenRay.Origin + (ScreenRay.Direction * GunData.ShotDistance))
local Forward = (ScreenPosition - Gun.Muzzle.Position).Unit
local Right = Forward:Cross(Vector3.FromAxis(Enum.Axis.Y))
local Up = Right:Cross(Forward)
local DirectionCFrame = CFrame.fromMatrix(Gun.Muzzle.Position, Right, Up)
local Direction = DirectionCFrame.LookVector * GunData.ShotDistance
Now the direction works, however it’s going diagonally through the position of the ScreenPosition.
Here’s a GIF of what’s happening:
I’d like it to go straight to the ScreenPosition, but I’m not sure how I can do that.
If any more information is required then I’ll be happy to supply it.