Ray isn't actually shoot at where mouse is aimed

My bullets in my FPS game are off centre when shooting. This isn’t due to any gravity effects, or what not. Even if I apply a straight ray, it’s still off centre.

local Direction = Camera.CFrame.LookVector.Unit

Before shooting


After shooting

This is a large disparity in shot position, and is causing a lot of players to get frustrated, as they have to adjust their aim.

Another example with normal gun, to prove its not just my scoped UI being off. Mouse did not move. The bullet should be right over where my mouse is.

1 Like

Thats because you added the .Unit on the LookVector. Try removing it

Even if I remove it, it doesn’t change the result :confused:

Why don’t you just use the players mouse position instead of the camera

I think the reason i changed it was cause players could press F9 (and thus their mouse is free) can now click anywhere on screen, and thus can shoot in an array of different positions

Can I see your shoot script/line

I use fast cast, which just passes a origin and direction value. The origin is the fire point at the end of the gun, and direction should be where you are aiming, so I don’t think anything else is necessary (other than the direction)

the cameras lookvector is in not in screen space. You need to cast a ray through the center of their screen by either a: using basic vector math or b: using robloxs built-in directional api
https://developer.roblox.com/en-us/api-reference/function/Camera/ScreenPointToRay

FPS games were simply never designed to be done on the server only and sadly cheaters will always exist. But there is different countermeasures, like for ex rate limiting the amount of requests (no one just spams remotes when it comes to machine guns, you send them in a packet of information, it’s the reason why in cod mw if you got bad internet you’ll get killed instantly and your headphones will make a loud noise)

Now thinking of it, i wonder if i do a cheeky thing here. Try putting this in your code and tell me if it works

local u = Vector3.new(0.5, 0.5, 1) --dont normalize/.Unit
local l = head.LookVector
local o = head.Position
local x = l/-o+u
local dir = u*x
local h = dir.Unit * 500
local actualDirSendThisToFastCast = (h-o).Unit --see what i did there lmao
2 Likes

Should head be the characters head??

I also tried

Camera:ScreenPointToRay(Mouse.X, Mouse.Y, 1).Direction

and that had no difference to previous attempts

Also, this is what your code does
ezgif.com-gif-maker (88)

I had a feeling it wouldnt work

have you tried this

local CameraPoint = Camera.CFrame.LookVector * 50
local ShotingDirection = (CameraPoint - "Bullet Start Position").Unit

That shoots them in the same sort of way as the gif above

you are using the FastCastRedux right?

Yes, I am using FastCastRedux

local Origin = firePoint
local Direction = Camera.CFrame.LookVector.Unit

local ActiveCast = Caster:Fire(Origin, Direction, SPEED, CastBehavior) -- Fire shot

Obviously SPEED and CastBehaviour are irrelevant to this problem

Search for the Fire function on the server side

function Fire(direction)

	if Tool.Parent:IsA("Backpack") then return end

	local directionalCF = CFrame.new(Vector3.new(), direction)

	local direction = (directionalCF * CFrame.fromOrientation(0, 0, RNG:NextNumber(0, TAU)) * CFrame.fromOrientation(math.rad(RNG:NextNumber(MIN_BULLET_SPREAD_ANGLE, MAX_BULLET_SPREAD_ANGLE)), 0, 0)).LookVector
	
	local humanoidRootPart = Tool.Parent:WaitForChild("HumanoidRootPart", 1)	
	local myMovementSpeed = humanoidRootPart.Velocity						
	local modifiedBulletSpeed = (direction * BULLET_SPEED)
	
	if PIERCE_DEMO then
		CastBehavior.CanPierceFunction = CanRayPierce
	end
	
	local simBullet = Caster:Fire(FirePointObject.WorldPosition, direction, modifiedBulletSpeed, CastBehavior)

	
	PlayFireSound()
end

Unsure where that is?

function FastCast:Fire(origin: Vector3, direction: Vector3, velocity: Vector3 | number, castDataPacket: FastCastBehavior?): ActiveCast
	if castDataPacket == nil then castDataPacket = DEFAULT_DATA_PACKET end
	
	local cast = ActiveCastStatic.new(self, origin, direction, velocity, castDataPacket)
	cast.RayInfo.WorldRoot = self.WorldRoot
	return cast
end
`local direction = (directionalCF * CFrame.fromOrientation(0, 0, RNG:NextNumber(0, TAU)) * CFrame.fromOrientation(math.rad(RNG:NextNumber(MIN_BULLET_SPREAD_ANGLE, MAX_BULLET_SPREAD_ANGLE)), 0, 0)).LookVector`


Now add a value to CFrame.fromOrientation on x and try if it fits

example:

local direction = (directionalCF * CFrame.fromOrientation(-0.05, 0, RNG:NextNumber(0, TAU)) * CFrame.fromOrientation(math.rad(RNG:NextNumber(MIN_BULLET_SPREAD_ANGLE, MAX_BULLET_SPREAD_ANGLE)), 0, 0)).LookVector

It’s inside a normal script not a module

FastCast is only modules
image

image