I have made a gun script, and it works perfectly fine, except for the fact that it runs too slow, so the bullet moves slowly and makes the game seem like it is in slow-motion. Here is a clip. As you can see, the bullet moves slowly. Do you have any idea on how to make it work faster? Any help is appreciated. Thank you!
local Mouse = LocalPlayer:GetMouse()
local RunService = game:GetService'RunService'
local function CalculateLandingPoint(Origin, Velocity, Dip, Orientation) -- Projectile flies from Origin with a Velocity vector
local StartTime = tick()
local StartPosition = Origin.Position
local OriginPos = StartPosition
local bullet = Instance.new("Part")
Orientation = Orientation + 90
bullet.Shape = Enum.PartType.Cylinder
bullet.Size = Vector3.new(1.2,0.2,0.2)
bullet.Position = OriginPos
bullet.Anchored = true
bullet.CanCollide = false
bullet.Parent = workspace
local LastPos
local CFrames = {}
while true do
if tick() - StartTime >= 3 then print("Unable to find object") break end
local Delta = RunService.RenderStepped:Wait()
local ray = Ray.new(StartPosition, Velocity)
local Hit, HitPosition = workspace:FindPartOnRayWithIgnoreList(ray,{LocalPlayer.Character})
if Hit then
break
else
if not LastPos then
LastPos = OriginPos
end
Velocity = Velocity - Vector3.new(0, workspace.Gravity * Delta / Dip,0) -- Divide by 100 so projectile doesn't fall too fast (for testing purposes)
StartPosition = HitPosition
local LookAngle = math.deg(math.sin((HitPosition.Y-LastPos.Y)/(HitPosition-LastPos).Magnitude))
LastPos = HitPosition
bullet.CFrame = CFrame.new(StartPosition) * CFrame.fromEulerAnglesXYZ(0,math.rad(Orientation),math.rad(LookAngle))
end
end
end
Mouse.Button1Down:Connect(function()
local Root = LocalPlayer.Character.PrimaryPart
local MouseCFrame = Mouse.Origin
CalculateLandingPoint(Root.CFrame, MouseCFrame.LookVector, 1000, Root.Orientation.Y)
end)```