Hello, I’m currently running into an issue I cannot seem to fix.
External Medialocal RayDirection = Gun.Muzzle.CFrame.LookVector * GunData.Range
Anyone know why the bullet Isn’t coming out of the muzzle when I begin to move?
Hello, I’m currently running into an issue I cannot seem to fix.
External Medialocal RayDirection = Gun.Muzzle.CFrame.LookVector * GunData.Range
Anyone know why the bullet Isn’t coming out of the muzzle when I begin to move?
The reason why the bullet is not coming out of the muzzle is because when you fired it, the bullet was in the position you were originally standing and that’s why the position looks like it is not.
I don’t understand and that doesn’t really make sense. In the video you clearly see the gun was not moving at all and is being faced relatively towards my mouse which is facing straight when I move to the sides the raycasting is literally being casted to the sides even though I’m going based off LookVector as in I’m raycasting based off where the muzzle is facing.
May I see your full script? Especially the part where the ray visual is created. That would provide some context that I can help you with. Thanks.
What samster said makes a lot of sense, while moving once you shoot the raycast shoots at the exact moment you left click and because you are moving, the bullet falls behind
The script below is under a RemoteEvent inside the ClientScripts
> local CreatedRay = Ray.new(Gun.Muzzle.Position, RayDirection)
>
> local RaycastDifference = CreatedRay.Origin + CreatedRay.Direction / 2
>
> local Part = Instance.new("Part")
>
> Part.Transparency = 0
> Part.CanCollide = false
>
> Part.CFrame = CFrame.lookAt(RaycastDifference, CreatedRay.Origin)
> Part.Size = Vector3.new(0.005, 0.005, CreatedRay.Direction.Magnitude)
>
> Part.Color = Color3.fromRGB(255, 255, 255)
> Part.Material = Enum.Material.Neon
>
>
> Part.Anchored = true
> Part.Parent = workspace
>
> game:GetService("Debris"):AddItem(Part, 0.05)
The script below is under a RemoteEvent inside the ServerScripts
> local Character = Player.Character
>
> local Gun = Character:FindFirstChildWhichIsA("Tool")
>
> local GunData = require(GunDataFolder[Gun.Name])
>
> local RayDirection = Gun.Muzzle.CFrame.LookVector.Unit * GunData.Range
>
> local RaycastParameters = RaycastParams.new()
>
> RaycastParameters.FilterDescendantsInstances = {workspace.Map.TargetFilter.Zombies}
> RaycastParameters.FilterType = Enum.RaycastFilterType.Include
>
> RaycastParameters.IgnoreWater = true
>
> local RaycastResult = workspace:Raycast(Gun.Muzzle.Position, RayDirection, RaycastParameters)
>
> if RaycastResult then
> local Hit, Position = RaycastResult.Instance, RaycastResult.Position
> print("Hit!")
> end
>
> game.ReplicatedStorage.Remotes.Raycast:FireClient(Player, RayDirection)
Yes I actually was wrong and it does make sense now, I think this is a good example of hit registration, I was raycasting on the client-side only and only had the server verify the damage / hit but now that I converted that it still doesn’t seem to work as I intend, any solutions?
Would you be able to say again what you intended?
I just want the bullets to shoot out directly from the muzzle