- What do you want to achieve?
A FPS gun that fires where where i aim my mouse
- What is the issue?
The raycast doesn’t even fire near where I want it to
- What solutions have you tried so far?
I’ve tried looking for some Roblox raycasting guides, tried using the camera as the origin of the gun, and tried changing some position values
local shootDistance = script.Parent.MaxShootDistance.Value
local rayOrigin = gun.effectsPart.Position
local rayDirection = mouse.Hit.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {char}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, (rayDirection - rayOrigin)*rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
print(model, hitPart)
if model then
if hitPart.Parent:FindFirstChild("Humanoid") then
hitPart.Parent.Humanoid.Health -= script.Parent.Damage.Value
end
end
end