When I shoot a projectile which is a part with a trail, it originates in the barrel of a viewmodel and uses a renderstepped loop to move it forward.
The issue I have is that when you fire projectiles in quick succession, it seems that they are being delayed and originating a few studs from the barrel. This effect seems to scale with speed of the bullet.
Below is a video of the issue and the function that is called when a projectile is fired.
If anyone can explain why this is that would be great!
mainModule.ClientProjectile = function(realCFrame, aestheticCFrame, destination,velocity, gun)
local diccctionary = {}
local projectile = RS.bullet:Clone()
projectile.Parent = game.Workspace
projectile.Size = Vector3.new(.1,.1,1)
projectile.CFrame = aestheticCFrame
local projectileStartVector = projectile.Position
local MovementLoop
local hitCheck = false
local previousRayCFrame
local rayCFrame = realCFrame
local distance = (destination - realCFrame.Position).Magnitude
local time = distance / velocity
local distance2 = (destination - aestheticCFrame.Position).Magnitude
local velocity2 = distance2 / time
local framed = 0
MovementLoop = game:GetService("RunService").Heartbeat:Connect(function()
framed +=1
--[[]]
--print((projectile.Position - aestheticCFrame.Position).Magnitude .. " frame: " .. (frame) .. " number: " )
diccctionary[framed]= {
frem = framed,
distancey = (projectile.Position - aestheticCFrame.Position).Magnitude
}
previousRayCFrame = rayCFrame
projectile.CFrame *= CFrame.new(0, 0, -velocity2 )
rayCFrame *= CFrame.new(0,0, -velocity)
local collisionCheck = workspace:Raycast(previousRayCFrame.Position, rayCFrame.Position - previousRayCFrame.Position)
if collisionCheck and hitCheck == false then
local objectHit = collisionCheck.Instance
local plrHit = game.Players:GetPlayerFromCharacter(objectHit.Parent)
hitCheck = true
print(collisionCheck.Instance)
projectile:Destroy()
MovementLoop:Disconnect()
mainModule.HitEffect(collisionCheck.Position , collisionCheck.Normal)
end
if (projectile.Position - projectileStartVector).Magnitude >= 100 then
projectile:Destroy()
MovementLoop:Disconnect()
end
end)
gun.GunComponents.Barrel.MuzzleEffect:Emit(1)
end