Mouse.Hit.Position returns position behind character when walking backwards

I’m currently making a bow using fastcast, and I’m trying to get the mouseposition. It’s supposed to mostly be used in 3rd person and shift lock. It works whenever I stand still and am walking forward, but whenever I try to walk backwards it returns a position that seems to be excactly where the camera is

Videos of the issue:
“Inside the bow”
Bow video
You can see that the arrows are flying towards the camera whenever I walk backwards

Printing mouse position:
Mouse print video
The X position is the main thing, it says accurately where I am looking normally, but when I begin walking backwards, it returns a position beside the character

I’ve tried making a raycast myself, but that didn’t work.
Another thing I’ve tried is mouse.hit.Lookvector, aswell as mouse.TargetFilter, like in this post: Mouse.Hit behind your character when you walk backwards? ,
but that didn’t work either
I do suspect that mouse.targetfilter or lookvector might be the solution, but I haven’t been able to find anything working.

the different things I’ve tried:
raw mouse.hit:

local function sendEvent()
	local mousePos = mouse.Hit.Position
	bowFireEvent:FireServer(mousePos)
end

Mouse target filters:

local function sendEvent()
	mouse.TargetFilter = player.Character
	mouse.TargetFilter = workspace.CurrentCamera
	local mousePos = mouse.Hit.Position
	bowFireEvent:FireServer(mousePos)
end

Raycast: (I know that this uses the camera lookvector and not the mouse position, but it still doesn’t work for some reason)

local function sendEvent()
local rayOrigin = workspace.CurrentCamera.CFrame.Position
	local rayDirection = workspace.CurrentCamera.CFrame.LookVector*1000
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {tool, player.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist 
	
	local raycastResult = workspace:Raycast(rayOrigin,rayDirection,raycastParams)
	local mousePos
	if raycastResult then
		mousePos = raycastResult.Position
	else
		mousePos = rayOrigin+rayDirection*1000
	end
	print(mousePos)
	bowFireEvent:FireServer(mousePos,power)
end

There’s probably some small thing that I’ve missed this whole time, but I’m really not sure, and I’ve tried fixing this problem for a good amount of time now.
Let me know if I need to provide anything else :slight_smile:

2 Likes

I’m not sure on if I did something wrong, but I still have the same problem.

I tried with the code you provided in the other post:

local function sendEvent()
local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {tool, player.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist 
	
	
	local mousePos = userInputService:GetMouseLocation()
	local viewportMouseRay = workspace.CurrentCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
	local rayCastResult = workspace:Raycast(viewportMouseRay.Origin, viewportMouseRay.Direction * 1000, raycastParams)
	local hitPosition
	if rayCastResult then
		hitPosition =  rayCastResult.Position
	else
		hitPosition = viewportMouseRay.Origin+viewportMouseRay.Direction * 1000
	end
	bowFireEvent:FireServer(hitPosition)
end

Clip showing:
video

You should also show your server code, you might need a direction vector and not a position vector.

Also you should verify the hit position is correct by creating an anchored part at the hit position. Visual debugging is always recommended.

1 Like

I tried with some visual debugging, and found that I had a part in front of the camera for some odd reason, I’m really not sure how I missed this, but thank you very much! :slightly_smiling_face:

1 Like

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