Need help with gun raycast!

Hello there, Im scripting gun and I tried to calculate the direction of the ray but it looks really weird I was doing debug and it was shooting this part to random positions, Im using

local RayResults = workspace:Raycast(Muzzle.CFrame.Position,(Muzzle.CFrame.Position - Mouse.Hit.p).Unit * 100)

If anyone can help me I would apreciate that!

I think you mixed the 2 up, you should be getting the Mouse’s Position first I believe?

local Direction = (Mouse.Hit.Position - Muzzle.CFrame.Position).Unit * 100
local RayResults = workspace:RayCast(Muzzle.CFrame.Position, Direction)

Also I’m pretty sure p is deprecated

1 Like