FastCast origin not updating

  1. What do you want to achieve?

I want to create a FPS system using FastCast

  1. What is the issue?

Everything works however, the origin of the bullet is not the muzzle of the gun even though I set it to the muzzle.

image

Video

  1. **What solutions have you tried so far?

I tried making sure that the position of the attachment is changing (There is an attachment in the muzzle of the gun from set as the origin)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Debris = game:GetService("Debris")

local currentGun = ReplicatedStorage:WaitForChild("Glock"):Clone()
local animController = currentGun.AnimationController
local animator = animController.Animator or Instance.new("Animator",animController)
local conn
local shootEvent = ReplicatedStorage:WaitForChild("Shoot")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local anims = {}

local currentState = "Idle"
local currentBullets = 15

repeat
	wait()
until game.Players.LocalPlayer.CharacterAdded



currentGun.Parent = workspace.Camera

for i,v in pairs(animController:GetChildren()) do
	if v:IsA("Animation") then
		anims[v.Name] = animator:LoadAnimation(v)
	end
end

anims["Equip"]:Play()

function lookAt(eye, target)
	local forwardVector = (target - eye).Unit
	local upVector = Vector3.new(0, 1, 0)
	local rightVector = forwardVector:Cross(upVector)
	local upVector2 = rightVector:Cross(forwardVector)

	return CFrame.fromMatrix(eye, rightVector, upVector2)
end


UIS.InputBegan:Connect(function(key)
	if currentState == "Idle" and key.KeyCode == Enum.KeyCode.R then
		currentState = "Reloading"
		
		local bulletToAdd = 15 - currentBullets
		local reloadSound = currentGun.Reload:Clone()
		
		reloadSound.Parent = currentGun
		reloadSound:Play()
		anims["Reload"]:Play()
		Debris:AddItem(reloadSound,reloadSound.TimeLength)
		
		wait(reloadSound.TimeLength)
		
		currentBullets += bulletToAdd
		currentState = "Idle"
	elseif currentState == "Idle" and key.UserInputType == Enum.UserInputType.MouseButton1 and currentBullets > 0 then
		local pos = currentGun.Handle.Attachment.Position
		
		currentState = "Shooting"
		currentBullets -= 1
		shootEvent:FireServer(mouse.Hit.p,pos,currentGun.Shoot.SoundId)
		
		anims["Fire"]:Play()
		
		wait(0.2)
		currentState = "Idle"
	elseif key.UserInputType == Enum.UserInputType.MouseButton1 and currentBullets == 0 then
		local shootSound = currentGun.Empty:Clone()
		shootSound.Parent = currentGun
		shootSound:Play()
		Debris:AddItem(shootSound,0.5)
	end
end)

conn = RunService.RenderStepped:Connect(function()
	currentGun.PrimaryPart.CFrame = workspace.Camera.CFrame
end)

Script

local Debris = game:GetService("Debris")
local FastCast = require(game.ReplicatedStorage:WaitForChild("FastCastRedux"))

local Caster = FastCast.new()

FastCast.VisualizeCasts = true

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		local newWeld = Instance.new("Motor6D",plr.Character)
		local clonedGlock = game.ReplicatedStorage:WaitForChild("GlockModel"):Clone()
		
		newWeld.Part0 = clonedGlock.Handle
		newWeld.Part1 = plr.Character.RightHand
		
		clonedGlock.Parent = plr.Character
		newWeld.C0 = CFrame.Angles(0,math.rad(180),0)
	end)
end)

game.ReplicatedStorage:WaitForChild("Shoot").OnServerEvent:Connect(function(plr,mousePos,origin,soundId)
	local direction = (mousePos-origin).Unit
	Caster:Fire(origin,direction,10000)
	
	local sound = Instance.new("Sound",workspace)
	sound.SoundId = soundId
	sound:Play()
	Debris:AddItem(sound,1)
	
	Caster.RayHit:Connect(function(cast,result)
		if result and result.Instance.Parent:FindFirstChild("Humanoid") and result.Instance.Parent.Name ~= plr.Name then
			local humanoid = result.Instance.Parent:WaitForChild("Humanoid")
			humanoid:TakeDamage(10)
		end
	end)
	
end)

Use .WorldPosition instead of Position. Attachments are special because their positions are attached relative to the parent part.

Ok, so I tried using WorldPosition and now the origin is from under the map

https://streamable.com/0l1kdd

Common problem, check this other post to see if it matches up.

1 Like

I tried out the solution yet the problem still persists

I also made sure to collision group changed

image

Figured out the problem, so since the attachment does not replicate to the server the origin of the ray changed.

To Fix: Weld a gun to the player’s hand on the SERVER and raycast it from there

Thanks to everyone who replied!