Tomorrow, I will be posting the tutorial about making your first GUI Based 2 dimensional game on Roblox! And this module will be included in the tutorial, so you can check that out as well for some more use cases of the module!
Added “solid” property to :addCollider(), setting it to true makes it impossible for a hitter to go through a collider! Example:
local GuiCollisionService = require(game.ReplicatedStorage.GuiCollisionService)
local group = GuiCollisionService.createCollisionGroup()
group:addHitter(guiInstanceHitter)
group:addCollider(guiInstanceCollider, true) -- To make it impossible for a hitter to go through the collider
Special thanks to @RuizuKun_Dev without whom, this wouldn’t have been possible, after understanding the math, I was able to figure out how easy this was to implement!
I am working on a 2D RayCasting module to help you cast rays even when the rotation of the gui is not 0 for 2D projectiles. Stay tuned!
There are a few bugs to this, which I have been fixing, thanks!
Tweens will now be cancelled if the hitter touches a solid collider!
Added tweens parameter to :addHitter(instance, tweens) function! which cancels those tweens if the hitter touches a solid collider! View Docs
Added :updateHitter(index, instance, tweens) function which updates already existing Hitters, their instance and their tweens! View Docs
Added :getHitterTweens(index) which returns all the existing tweens of the hitter that are being played or haven’t been played yet. View Docs
:addHitter() and :updateHitter() function now return the hitter that was added which can be used as follows:
local addedHitter = group:addHitter(script.Parent.Hitter, { tween, tween2 })
addedHitter.index -- index of the hitter
addedHitter.instance -- the instance that was marked as the hitter, here: script.Parent.Hitter
I have also been playing around with Gui Collisions when the guis are rotated, next update will consist of gui collisions even if the guis are rotated.
Added :setZIndexHierarchy(boolean). The function is used to determine if the hitter will collide with colliders that have different ZIndex values. Setting it to true, will make the hitter not detect collisions with colliders that have different ZIndex value than the hitter. Setting it to false, will make the hitter collide with colliders no matter what their ZIndexes are. By default this is set to false.View Docs
This feature can be used to create Slopes in 2D Games, slanting roads, caves, objects you can’t go through but can go behind and in front of them, by changing the hitter’s ZIndex. For example:
Added .isInCore() function. This function is used to determine if a gui object is completely inside of the area of another gui. This function returns true if a gui is completely inside of another, else it returns false. If guiHitter’s size is smaller than that of guiCollider, the function returns false. View docs
Video Examples:
(ignore the “too” misspell)
This works with tweens as well!
Example Code:
local GuiCollisionService = require(game.ReplicatedStorage.GuiCollisionService)
print(GuiCollisionService.isInCore(someHitterInstance, someCollider)) -- prints true if hitter is completely inside the area of the collider, else false
Use Cases
This function can be used to create Rhythm game scoring mechanics. For example a “Perfect hit” or a “Miss”
After a fairly long wait. The update you all have been waiting for is finally out! (sorry for the long wait)
This module now perfectly detects collisions for rotated Guis! How? Its fairly simple! With the concept of ray casting. Each point casts a ray on the x axis, if the ray intersects with any of the edges of the gui and if the point lies inside the gui object, both guis intersect! No matter what the rotation of the guis are!
Example Code for the video
local GuiCollisionService = require(game.ReplicatedStorage.GuiCollisionService)
local group = GuiCollisionService.createCollisionGroup()
--GuiCollisionService.
group:addCollider(script.Parent.Still, false)
group:addCollider(script.Parent.Still2, false)
group:addCollider(script.Parent.Still3, false)
group:addHitter(script.Parent.Move, {})
group:getHitter(1).CollidersTouched.Event:Connect(function(hits)
group:getHitter(1).BackgroundColor3 = Color3.new(0.333333, 1, 0)
end)
group:getHitter(1).OnCollisionEnded.Event:Connect(function()
group:getHitter(1).BackgroundColor3 = Color3.new(255,255,255)
end)
Currently this does not work with solid colliders as expected. But works perfectly otherwise! Will be added to solid colliders soon!
I’m sorry to bump, but this is insane, and I love it.
I’ve made something similar to this before, but with support for UICorner frames. That was a nightmare; never again.
Few slight modifications I might suggest:
Make collision groups “destroyable” (This could be useful if you wish to do some minor optimization i.e removing “game” state groups in a start menu.)
This could be accomplished by using BindToRenderStepped to make the RenderStepped connections removable, since as far as I can see right now, they are just connected with no references.
Use Attributes instead of Value objects
Pretty self-explanatory
And that’s pretty much all that I can immediately suggest.
Once again, sorry to bump this; but I had to since I thought to suggest these changes after reviewing the source.