i’m making a viewmodel thing and the bullets sometimes get ejected in slow motion. it doesn’t happen when they’re un-cancollided or have no rotvelocity
so ig that just decreased the chance of it happening? i originally marked this as the solution because after like 6 times of testing it, it worked fine, but now it’s starting to happen again just at random
local bullet = repStorage.Bullet:Clone()
bullet.Parent = workspace
bullet.CFrame = viewmodel.Gun.Slide.CFrame * CFrame.Angles(0,math.rad(180),0)
bullet.AssemblyLinearVelocity = bullet.CFrame.RightVector * 15 + Vector3.new(0,10,0)
bullet.AssemblyAngularVelocity = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
while wait(.1) do --(this is here to make the bullet stop moving when it hits the ground)
local part = workspace:FindPartOnRay(Ray.new(bullet.Position,Vector3.new(0,-.075,0)),bullet)
if part then
bullet.Anchored = true
bullet.CanCollide = false
wait(10)
bullet:Destroy()
break
end
end
Use task.wait() instead of wait(), wait() throttles. This issue might be based on your fps, try with a high framerate and low framerate. If it is, you need to take account for delta time which you can retrieve by either using task.wait() or RunService.Heartbeat:Wait().
My theory is that it may be occurring due to too many physics objects being created. Perhaps introducing a queue of sorts to keep track of how many were created would help? You could also use that collision group thing to prevent the shells from merging with the gun, which seems to be what your code’s attempting to accomplish.
yeah it has no collision either
it kind of makes sense why the collision group worked since when the bullet just flat out had no collision and fell through the map, it worked fine. i only started having the slow-mo issue when i enabled cancollide
That’s just what I was thinking as well. It’s subject to the same throttling issue as wait() and has a high max item queue.
Personally I believe that wait(n) is fine unless you’re depending on constant precision and consistency in your program. If it’s not needed, then using wait(n) here or there is a non-issue.
didn’t mean deprecated in the literal sense, it was because you said wait() and vector3 were deprecated (which I’m assuming you mean not advised to use)
as said above it’s subject to a throttling issue like wait(), and fwik there’s no better alternative that isn’t user-created
Actually now that I think about it, you could change how that works. You could utilize the collision group to have the bullet not interact with the player character / gun, and then use Touched for when it touches the ground, completely eliminating having to utilize a loop.
local tconn = nil
tconn = bullet.Touched:Connect(function()
if tconn.Connected == false then
return
end
local part, pos = Workspace:FindPartOnRay(Ray.new(bullet.Position, Vector3.new(0, -2, 0)), bullet)
if part ~= nil and (bullet.Position - pos).Magnitude <= 0.75 then
tconn:Disconnect()
Debris:AddItem(bullet, 10)
bullet.Anchored = true
bullet.CanCollide = false
end
end)