At the moment, I am using BodyMovers (BodyVelocity in particular) to move my instantiated bullet tracers in a straight line. In general, this works okay- but there is one prevalent issue which has always been present (even in my previous gun-scripts which used similar methods): the tracers starting ahead of where they should be whenever I fire my guns at a relatively fast fire-rate.
As a preface, these tracers are spawned purely locally.
I will start by demonstrating what it SHOULD appear like:
You can see that the bullet tracer emits directly from the barrel of the gun.
However, when I begin to fire quickly, the tracers after the first shot appear to be spawning with correct orientation and speed, but incorrect origin.
https://i.gyazo.com/b14bf6d0d543bf14e6031cfb7ab98ece.mp4
You can see that the bullet tracers do not appear to emit directly from the barrel of the gun, but some distance in front.
Here is the hierarchy of the bullet tracer that gets cloned:
Here is the code inside of the ‘Run’ ModuleScript which runs every time a tracer is instantiated:
local CFrameNew = CFrame.new
local InstanceNew = Instance.new
local Vector3New = Vector3.new
local MathHuge = math.huge
local TweenService = game:GetService('TweenService')
return function(Origin, Direction, Speed, Parent)
Origin = Origin or CFrameNew(0, 0, 0)
Direction = Direction or CFrameNew(0, 0, 0)
Speed = Speed or 800
Parent = Parent or workspace
script.Parent.CFrame = CFrameNew(Origin, Direction)
script.Parent.Name = "Tracer"
local BodyVelocity = InstanceNew("BodyVelocity")
BodyVelocity.MaxForce = Vector3New(MathHuge, MathHuge, MathHuge)
BodyVelocity.Velocity = script.Parent.CFrame.LookVector * Speed
BodyVelocity.Parent = script.Parent
TweenService:Create(BodyVelocity, TweenInfo.new(.4), {
Velocity = script.Parent.CFrame.LookVector * Speed/15
}):Play()
game.Debris:AddItem(script.Parent, 2)
script.Parent.Parent = Parent
end
…and the arguments passed into it:
Run(Muzzle.CFrame.Position, position, Config.bullet_speed or 3200, TargetFilterFolder)
I’ve been stuck on this issue for quite a while, and I’m leaning towards believing that the issue lies in the behavior of BodyVelocity.
The only solution I have discovered is reducing the tracer’s speed, but at the point the tracer travels very slow.
If I missed out on any needed information, please let me know. Thanks.