FastCast ray not keeping up with character when moving

Basically, I’m trying to make the bullet/ray fire exactly where the humanoid root part is stationed when firing, to shoot directly ahead, and it seems to lag behind, I’ve noticed that when I playtest the game it makes a noticeable impact on aiming, and I’d really like to know why it’s doing this (This uses fastcast, by the way)

The specific code used to shoot out the ray in the direction the player

local function fire(player)
	if db ~= false then
	db = false
	local sound = tool.FireSound.Value
		workspace.Gun.SoundId = "rbxassetid://"..sound
	local origin = tool.Parent.HumanoidRootPart.Position -- here is where the ray originates from
	local direction = tool.Parent.HumanoidRootPart.CFrame.LookVector * 500 -- and right here is how the ray calculates the direction.
	caster:Fire(origin, direction, 500, castBehavior)
	db = true

If anyone knows any solutions I’d be greatful.

Here the direction is multiplied by 500, and the distance is 500 too so the direction becomes
tool.Parent.HumanoidRootPart.CFrame.LookVector * 250000 I am not sure whether this would cause the issue but this is a very long ray. I believe that you could use remove * 500 when you define direction.

Correct me if I am wrong, I haven’t used FastCast before.

The direction line multiplied LookVector * 500 which makes the ray fire 500 studs forward, while the 3rd parameter is the velocity of how fast the rays casted will fly, being 500.

Oh my bad , I thought it was the length of the ray casted.

There’s nothing wrong with your code, it’s just that it’s a flaw in fastcast to start rendering the raycasts at the first frame.

1 Like

Well, that quite strange, hopefully players will get used to the slight movement delay then, it hopefully shouldn’t affect too much, thank you for all your answers regardless!