Issue with FireCast Module

Please watch the video below for what I’m saying to make sense

As you can see its a top down shooter game, very early in the works, anyways the player has a local script inside of starterplayerscripts rotating the root to the mouse hit, heres thats script:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local char = player.Character or player.CharacterAdded:Wait()

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local moveForwardsEvent = ReplicatedStorage.Movement.Forwards

local UIS = game:GetService("UserInputService")

local root = char:WaitForChild("HumanoidRootPart")

local RS = game:GetService("RunService")

local mouse = player:GetMouse()

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {char}

function cameraAdjust()
	local Height = Vector3.new(0, 40, 0)
	local rotation = CFrame.Angles(math.rad(-90), math.rad(0), math.rad(0))

	camera.CFrame = CFrame.new(root.Position + Height) * rotation
end

mouse.Move:Connect(function()
	local MousePos = mouse.Hit.Position
	
	local direction = (MousePos - root.Position).unit

	root.CFrame = CFrame.lookAt(root.Position, Vector3.new(mouse.Hit.X, root.Position.Y, mouse.Hit.Z))
end)

mouse.Button1Down:Connect(function()
	local direction = root.Position - mouse.Hit.Position
	local raycast = workspace:Raycast(root.Position, direction, raycastParams)


--	moveForwardsEvent:FireServer(true)
end)

mouse.Button1Up:Connect(function()
	--moveForwardsEvent:FireServer(false)
end)



RS:BindToRenderStep("Camera", 210, cameraAdjust)

The script using FireCast is this

local tool = script.Parent
local shootEvent = script.Parent:WaitForChild("Shoot")

local BulletsFolder = game.Workspace:WaitForChild("Bullets")

local FastCast = require(game.ReplicatedStorage.FastCastRedux)
-- FastCast.VisualizeCasts = true
local castBehavior = FastCast.newBehavior()

local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true


local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Size = Vector3.new(0.1, 0.1, 4) 
bulletTemplate.Material = Enum.Material.Neon
bulletTemplate.BrickColor = BrickColor.new("Yellow flip/flop")

castBehavior.RaycastParams = castParams
castBehavior.CosmeticBulletContainer = BulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate

local function Hit(cast, result, velocity, bullet)
	local hit = result.Instance
	local character = hit:FindFirstAncestorWhichIsA("Model")
	if character and character:FindFirstChild("Humanoid") then
		character.Humanoid:TakeDamage(20)
	end
	
	if bullet then
		bullet:Destroy() 
	end

end

local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
	if bullet then
		local bulletLength = bullet.Size.Z / 2
		local offset = CFrame.new(0, 0, -(length - bulletLength))
		bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
	end
end

local function equipped()
	castParams.FilterDescendantsInstances = {tool.Parent, BulletsFolder}
end

local caster = FastCast.new()

local function shoot(player, mousePosition)
	local firePoint = script.Parent.Barrel.FirePoint
	local origin = firePoint.WorldPosition
	local direction = player.Character.HumanoidRootPart.CFrame.LookVector.Unit

	caster:Fire(origin, direction * 100, 100, castBehavior)
end



tool.Equipped:Connect(equipped)
shootEvent.OnServerEvent:Connect(shoot)
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(Hit)

If the player rotates too fast the bullet will be delayed, not firing from the tip of guns barrel, as it should.

Help is appreciated

1 Like

you could send the position of firePoint to the server, instead of the server handling it themselves.

that wont fix the issue, it will still be delayed

have you tried it yet, why wouldnt it work.

It wouldn’t work because getting the same data on the client that the server has, sending it and using that data on the module yields the exact same results as getting the data on the server and using it without the client sending it over on the module, its the same exact data.

But I tried it regardless, didn’t work

I would imagine this is just network latency. I would suggest rendering the projectile on the client separately and perform the “real” projectile hit registration on the server, just don’t have an actual part for it on the server.

2 Likes

I am using fire cast but ill try doing all of it on the client

Tried it, the delay is not entirely gone but is noticeable less so I’ll give you solution anyways, thanks

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