Whenever more than one projectile is launched, the recent one will position at the same offset of the last one and is not independent from the last projectile
EDIT : Also it seems like the next launched projectile speed is always speeding up
[You can test this script on studio)
local player = game.Players.LocalPlayer
local character = player.Character
local camera = game.Workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local lastProjectile = -tick()
local t = tick()
local dt
local Projectiles = {}
local Input = {}
local Trajectory = {}
do
local self = Projectiles
self.Position = Vector3.new()
self.Velocity = Vector3.new()
self.CreateProjectile = function()
local projectile = Instance.new("Part", workspace)
projectile.Size = Vector3.new(0.5, 0.5, 5)
projectile.CFrame = character.HumanoidRootPart.CFrame
projectile.Position = CFrame.new(character.HumanoidRootPart.CFrame.lookVector * 10).p
projectile.Anchored = true
projectile.CanCollide = false
projectile.Material = Enum.Material.Neon
projectile.BrickColor = BrickColor.new("Copper")
self.Position = projectile.Position
table.insert(Trajectory, projectile)
delay(3, function() self.Clear(projectile) end)
end
function self.Clear(projectile)
if projectile then
projectile:Destroy()
for i, projectile in pairs(Trajectory) do
if Trajectory[i] then
Trajectory[i] = nil
end
end
self.Position = Vector3.new()
self.Velocity = Vector3.new()
self.Gravity = Vector3.new()
end
end
self.Trajectory = function(initial, velocity, delta)
return initial + velocity * delta
end
self.Update = function(delta)
for i, projectile in ipairs(Trajectory) do
self.Velocity = self.Position + self.Velocity * delta
self.Position = self.Velocity
projectile.Position = self.Position
end
end
end
do
local self = Input
self.key = {}
uis.InputBegan:connect(function(inp, gpe)
if gpe then return end
self.key[inp.KeyCode.Value] = true
end)
uis.InputEnded:connect(function(inp, gpe)
if gpe then return end
self.key[inp.KeyCode.Value] = false
end)
end
local function load()
player.CameraMode = Enum.CameraMode.LockFirstPerson
character.Humanoid.JumpPower = 0
end
load()
rs:BindToRenderStep("Update", 201, function()
dt = tick() - t
t = tick()
if Input.key[32] and tick() - lastProjectile > 0.5 then
lastProjectile = tick()
Projectiles.CreateProjectile()
end
Projectiles.Update(dt)
end)
