I’m currently making a third person game where some characters can shoot, and in most situations it works fine! However since it is third person, it’s possible that your camera can be aiming at something that is behind you. As you can see in the image, it will shoot backwards at the brick.
Here is the code that handles shooting:
function shootM1()
local currentCamera = workspace.CurrentCamera
local VIEWPORT_SIZE = currentCamera.ViewportSize
local unitRay = currentCamera:ViewportPointToRay(VIEWPORT_SIZE.X / 2, VIEWPORT_SIZE.Y / 2)
local originPoint = originPoint.Position
local myParams = RaycastParams.new()
myParams.FilterType = Enum.RaycastFilterType.Exclude
myParams.FilterDescendantsInstances = {myCharacter}
local hitscan = workspace:Raycast(unitRay.Origin, unitRay.Direction*1000, myParams)
local focalPoint = if hitscan then hitscan.Position else unitRay.Origin+unitRay.Direction*1000
local direction = CFrame.lookAt(originPoint, focalPoint).LookVector
local extraArgs = {direction, originPoint} --n.
weapon.AbilityHandler:FireServer("m1", extraArgs)
end
I’m more so just looking for advice on the best way to prevent this, and the best solution on what to do when this happens!
