I was working on my FPS framework when I came across a problem. Anytime I tried to make my gun shoot using fastcast, the bullets origin would be way under the player. When I go into server mode and then switch back to the client it just fixes it and I really don’t know why. If anyone could help me solve this problem I would really appreciate it.
This video shows the problem I’m having
This video is how I get it to stop doing placing the origin under the player.
I suggest not to use fastcast for your case because what I have seen from the video is you casting only a single ray while fastest is used to cast multiple rays in one moment. Also if you could show the script so that we are able to help you determine the origin of the problem that will be great.
Client:
--Mouse inputs--
mouse.Button1Down:Connect(function()
if primary then
local barrel = primary.weapon.Hole
local ignoreList = RaycastParams.new()
ignoreList.FilterType = Enum.RaycastFilterType.Blacklist
ignoreList.FilterDescendantsInstances = {char, camera}
local hit = workspace:Raycast(barrel.Position, barrel.CFrame.LookVector * 10000, ignoreList)
shoot:FireServer(primary.weapon.Barrel.Distpart.WorldPosition, barrel.Position)
end
end)
Server:
--Shooting--
local caster = fastCast.new()
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater = true
castParams.FilterDescendantsInstances = {char}
local castBehavior = fastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0,-workspace.Gravity,0)
castBehavior.AutoIgnoreContainer = false
fastCast.VisualizeCasts = true
local function fire(plr, mousePos, holePos)
local weapon = plr.WeaponInfo.Primary.Value
local module = require(game.ReplicatedStorage.Modules:FindFirstChild(weapon))
local origin = holePos
local direction = (mousePos - origin).Unit
print(mousePos," Mouse Pos")
print(holePos," Hole pos")
print(origin, "origin")
print(direction, "dir")
caster:Fire(holePos, direction, module.MuzzleVelocity,castBehavior)
end
shoot.OnServerEvent:Connect(fire)
And I do need to use fastcast since I’m not smart enough to create my own bullet drop and simulate bullet travel time.
I have a ton of scripts of that if you would like I can show you the basics on how to do so.
I would suggest to compared the position on the client and then on the server by printing it and see the outcome.
I would appreciate that since FastCast has been giving me quite a few problems
I’ve done that but I’m thinking it has something to do with the actual module itself
They do have the same position, so it’s likely that it’s actually a problem with fastcast or something else, since it only starts working when I switch from client to server to client.
I’ve worked with FastCast before, and it’s pretty reliable. Also, the prints show that the origin is already well below the character before FastCast messes with it, so I think it’s a problem with barrel.Position
.
The origin is not below the player I’ve testing before switching to the server and after. I know exactly where the barrel is at all times, I really don’t know what happens to it afterward tho
In the first video, it shows the origin
is around y = -84, so it is something with barrel
. Have you tried printing on the client?
Oh I see what you mean, I thought you were talking about the screen shot I just sent.
Okay yeah the hole is way underneath the player but I’m not too sure why. I think I’ll change it from motor 6d to a weld
Can you highlight where the barrel is to show where it is before and after the fix and show the video?
Yeah now its a problem where the attachments move whenever they want to.
Okay so after I messed around with a few things I learned that I have to anchor the parts other wise it will just bug out and since it is anchored I cannot use animations. So from now on I’ll just have to use CFrame animations.
You can convert regular animations to cframe animations but it will be tricky.
Yeah I don’t really have a choice so I’ll just deal with it.