Fastcast bullets offset in third person

In the supplied screenshots, you can clearly see that the bullets are not going exactly where my mouse (crosshair) is.

I’m not sure if this is a Fastcast issue or if I’m not using the ScreenPointToRay() method correctly or something else entirely.

	if firstPerson then
		muzzle = curModel.Grip.Muzzle.WorldCFrame.Position
		bulletOrigin = workspace.CurrentCamera.CFrame.Position
		bulletDirection = (workspace.CurrentCamera.CFrame * spreadCFrame).LookVector
		muzzle = weaponRig.Weapon:FindFirstChildWhichIsA("Model").Grip.Muzzle.WorldCFrame.Position
		local head = character.Head
		bulletOrigin = head.Position
		local unitray = camera:ScreenPointToRay(mouse.X, mouse.Y)
		bulletDirection = unitray.Direction.Unit

You are using the direction from the camera to the mouse location rather than the direction from the muzzle to the mouse location. To fix this, you’d actually use the ray to do a raycast and then find the hit, using the range * unit vector of the position of the hit minus the muzzle position to then cast the bullet.

1 Like

I’m a bit confused, like this?

muzzle = weaponRig.Weapon:FindFirstChildWhichIsA("Model").Grip.Muzzle.WorldCFrame.Position
bulletOrigin = muzzle
local mousePos = mouse.Hit.Position
bulletDirection = (mousePos - bulletOrigin).unit

It seems to work

Yes, mouse.Hit also works. Should work fine on mobile too. People use screenpointtoray when they don’t wanna work with the mouse object and want more control over what parts query the mouse.

1 Like

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