You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I am attempting to make a cannon that shoots in an arc. I can make the part do an arc well but for some reason it is lagging a lot eve though it is using stepped. -
What is the issue? Include screenshots / videos if possible!
The part is lagging a lot while its in flight but when It disconnects from the stepped it is fine.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
function ProjectileService:FireProjectile(startingPos, Force)
local projectile = script.Projectile:Clone()
projectile.Position = startingPos
projectile.Parent = workspace
local connection
local startTime = workspace.DistributedGameTime
local startingV = 100
local startingH = startingPos.Y
connection = RunService.Stepped:Connect(function()
local timeinSeconds = workspace.DistributedGameTime - startTime
--currentHeight = quadratic coefficent * gravity(m/s^2) * TimeInSeconde^2 + (StartingVelocity m/s^2 * TimeInSeconds) + height
local currentHeight = (-.5) * (54.936) * (timeinSeconds^2) + (startingV * timeinSeconds) + startingPos.Y
projectile.CFrame = CFrame.new(projectile.Position.X + 1, currentHeight, projectile.Position.Z)
if currentHeight <= -1 then
connection:Disconnect()
end
end)
end