TouchedPlus
Raycast Based Collision Detection For Cuboids
Robloxs Built in Touched & TouchEnded events are sensitive and near unusuable. I haven’t since found a good, fast and performant alternative to this - so decided to make one. Even Zone+ has limitations as it uses Region3 which is more costly than raycasting. I also wanted to offer much more control to the developer to decide the balance on accuracy, speed and performance.
So without further ado, here is “TouchedPlus”, name undecided. It’s a performant, no fuss collision detection module for cuboids and BaseParts:
Accurate Collision Detection for BaseParts, compatible with all primitive objects but made for cuboids.
In The Future I may expand the scope of what this can handle but have no plans as of yet, was more of a fun experiment. If you find any issues do let me know but uh - hope you enjoy!
Examples:
Adds Touched & Touch Ended for one BasePart.
local TouchedPlus = require(game:GetService("ReplicatedStorage").TouchedPlus)
local partDetection = TouchedPlus.new(script.Parent, 10)
--object, precision, optional [delay] (otherwise automatically determined based on precision to balance performance)
partDetection.Touched:Connect(function(obj)
print("touched: ", obj.Name)
end)
partDetection.TouchEnded:Connect(function(lastObj)
print("touch ended on: ", lastObj.Name)
end)
Playground Uncopylocked
*The Above example uses Knit Components for the Coins and references Knit for the Modules. Knit is a framework by @Sleitnick. If you don’t use Knit you can grab the module, dependencies included, below:
https://www.roblox.com/library/6159538577/TouchedPlus
Documentation:
To setup a collision you just create a new class, like so: local variableName = TouchedPlus.new()
It accepts three parameters, with two advised:
- Object BasePart [Required]
- Integer Accuracy [Optional]
- Boolean Dynamic [Optional]
- Float Speed/Delay [Optional - else automatically calculated]
I’ve tried to mimic robloxs API as closely as possible for this, to detect collisions we have .Touched & .TouchEnded, for cleaning up the class and removing detection :Destroy().
Any questions, drop them below and i’ll do my best