local raycastingModule = {}
local a = game.Workspace.a
local b = game.Workspace.B
local function RayLaser(startPos, endPos)
local rayLaser = Instance.new("Part", workspace)
rayLaser.Name = "Raylaser"
local distance = (endPos - startPos).Magnitude
rayLaser.CanCollide = false
rayLaser.CanTouch = false
rayLaser.Anchored = true
rayLaser.Size = Vector3.new(0.1, 0.1, distance)
rayLaser.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -distance/2)
rayLaser.Color = Color3.fromRGB(55, 255, 24)
game:GetService("Debris"):AddItem(rayLaser, 0.1)
return rayLaser
end
while true do
local directionofray = b.Position - a.Position
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {workspace.Window}
local RaycastingResult = workspace:Raycast(a.Position, directionofray, params)
local rayLaser = RayLaser(a.Position, a.Position + directionofray)
if RaycastingResult and RaycastingResult.Instance then
if RaycastingResult.Instance == b then
b.Color = Color3.fromRGB(89, 255, 0)
rayLaser.Color = Color3.fromRGB(55, 255, 24)
else
b.Color = Color3.fromRGB(255, 0, 0)
rayLaser.Color = Color3.fromRGB(255, 0, 0)
end
end
print(RaycastingResult)
task.wait(0.5)
end
return raycastingModule
#How can i implement Object Pooling inside of this module
1 messages · Page 1 of 1 (latest)
I want to use Object pooling instead of constant Instantiation to make the raycast more optimized
a method i've seen is just having a bunch of parts placed at an extremely high cframe, then teleporting them
there was a module for it
i forgot what it was calle
https://devforum.roblox.com/t/pooler-lets-go-for-a-swim-in-the-part-pool/1677672/4
https://devforum.roblox.com/t/objectpool-module-for-cloning-objects-without-lags/3059330
Developer Forum | Roblox
To be fair though, I wouldn’t be surprised if a FPS game benefited a ton from this, with the constant creation and destruction of bullets. It may not seem like a big difference but as @lewisakura said it all adds up in the end.
Developer Forum | Roblox
ObjectPool Module Overview The ObjectPool module provides a mechanism for efficiently managing objects without causing FPS drops. It allows objects to be reused rather than recreated, optimizing performance and resource usage. Usage Initialization: Create an instance of ObjectPool using ObjectPool.new() with specified object template, cre...
id recommend looking into the scripts of these
i dont have an exact script for the implementation so these will help you get a general idea of how to go about implementing object pooling
by viewing the modules and such and what they do
i hope this helps somewhat, i recommend looking into these things before opening up a post because there are a lot of posts regarding object pooling, and you could probably find a devforum post that suits you and your needs, even if it's not directly related.
i assume this is a fairly common topic as raycasting and spawning instances can take up a lot of performance, and for some games like tds with a lot of bullets and effects, you need an effective solution for them.
have fun!
i think you could do this by having a set of bullets, and then cloning a new one for use everytime you fire one, so it is just an infinite stock?
isnt that exactly what object pooling intends to defeat?
because cloning creates a new object, which is expensive
this is good because reparenting is a bit more expensive than repositioning