Hello
I’m not entirely sure how to explain this, but I’ve had a lot of trouble with my gun framework raycasting in old camera positions that should be updated to a new area.
https://gyazo.com/dca874cfa9dc25dc77fc1767e96758a1
https://gyazo.com/e054eb4bc868c45c56f2ac6423d54773
I know this occurs when you move your camera really fast, and thereby causing the script to update from an older position, but I wanted to know how you can keep it more precise to where the camera is pointed instead.
Here is the code:
local CamPos = Cam.CFrame.Position
local Direction = Cam.CFrame.LookVector
local chosenInacc = Vector3.new(math.random(-Diverge, Diverge), math.random(-Diverge,Diverge), math.random(-Diverge,Diverge))*currInaccuracy*.005
Direction += chosenInacc
local Ray = workspace:Raycast(CamPos, Direction * 500, Params)
if Ray then
local Result = Ray.Instance
local ResultPos
if Result.Transparency == 1 then
Params.FilterDescendantsInstances = {Params.FilterDescendantsInstances, Result}
Ray = workspace:Raycast(Ray.Position, Direction * 1500, Params)
if Ray then
Result = Ray.Instance
else
Fire:FireServer(Ray.Position)
return
end
end
ResultPos = Ray.Position
Fire:FireServer(Result, ResultPos)
end
recoilCF = recoilCF:Lerp(CFrame.Angles(math.rad(Recoil),0,0),.03)
VMAnims.Shoot:Play()
NormalAnims.Shoot:Play()
vModel.Handle.A0.Spark:Emit(1)
This script is on the client, but it was recently changed from server validation in the hopes that I could rectify this problem. I’m hoping that I can move back to server validation if anyone can provide a better method for raycasting bullets.